r94776 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94775‎ | r94776 | r94777 >
Date:17:05, 17 August 2011
Author:vasilievvv
Status:deferred
Tags:
Comment:
Yet another change to addition operator behavior:
* Make it to return the same array when array and null are added, e.g. [2,3] + null = [2,3]
Modified paths:
  • /trunk/extensions/WikiScripts/interpreter/Data.php (modified) (history)
  • /trunk/extensions/WikiScripts/interpreterTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiScripts/interpreter/Data.php
@@ -218,6 +218,14 @@
219219 }
220220
221221 public static function sum( $a, $b, $module, $line ) {
 222+ // If one operand is array and other is null, return the array
 223+ if( $a->isArray() && $b->type == self::DNull ) {
 224+ return $a->dup();
 225+ }
 226+ if( $b->isArray() && $a->type == self::DNull ) {
 227+ return $b->dup();
 228+ }
 229+
222230 // Lists
223231 if( $a->type == self::DList && $b->type == self::DList )
224232 return new WSData( self::DList, array_merge( $a->toList(), $b->toList() ) );
Index: trunk/extensions/WikiScripts/interpreterTests.txt
@@ -673,3 +673,35 @@
674674 </p>
675675 !! end
676676
 677+!! article
 678+Module:Using append with arrays
 679+!! text
 680+function testAssoc() {
 681+ append { "a" : 2 };
 682+ append { "b" : 3 };
 683+}
 684+
 685+function testList() {
 686+ append [ 1, 2 ];
 687+ append [ 3, 4 ];
 688+}
 689+
 690+function main() {
 691+ for( k : v in self::testAssoc() ) {
 692+ append k + " = " + v + "; ";
 693+ }
 694+
 695+ for( v in self::testList() ) {
 696+ append v + "; ";
 697+ }
 698+}
 699+!! endarticle
 700+
 701+!! test
 702+Using append with arrays
 703+!! input
 704+{{s:Using append with arrays}}
 705+!! result
 706+<p>a = 2; b = 3; 1; 2; 3; 4;
 707+</p>
 708+!! end

Status & tagging log