Index: trunk/extensions/WikiScripts/interpreter/Data.php |
— | — | @@ -218,6 +218,14 @@ |
219 | 219 | } |
220 | 220 | |
221 | 221 | 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 | + |
222 | 230 | // Lists |
223 | 231 | if( $a->type == self::DList && $b->type == self::DList ) |
224 | 232 | return new WSData( self::DList, array_merge( $a->toList(), $b->toList() ) ); |
Index: trunk/extensions/WikiScripts/interpreterTests.txt |
— | — | @@ -673,3 +673,35 @@ |
674 | 674 | </p> |
675 | 675 | !! end |
676 | 676 | |
| 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 |