2 # Copyright (C) 2001-2007, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 30;
13 t/pmc/sarray.t - Simple Array
17 % prove t/pmc/sarray.t
21 Tests the C<SArray> PMC, which is used for parameter-passing.
25 my $fp_equality_macro = pasm_fp_equality_macro();
27 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting sarray size" );
46 pasm_error_output_like( <<'CODE', <<'OUTPUT', "attempt resize" );
65 pasm_output_is( <<'CODE', <<'OUTPUT', "indexed access" );
105 pasm_output_is( <<'CODE', <<'OUTPUT', "push" );
145 pasm_output_is( <<'CODE', <<'OUTPUT', "push / indexed" );
185 pasm_output_is( <<'CODE', <<'OUTPUT', "mixed indexed" );
218 pasm_output_is( <<'CODE', <<'OUTPUT', "mixed push" );
251 pasm_output_is( <<'CODE', <<'OUTPUT', "mixed push - clone" );
286 pasm_output_is( <<'CODE', <<'OUTPUT', "shift_integer" );
326 pasm_output_is( <<'CODE', <<'OUTPUT', "mixed shift" );
359 pasm_output_is( <<'CODE', <<'OUTPUT', "iterator" );
360 .include "iterator.pasm"
361 new P0, 'SArray' # empty array
362 new P2, 'SArray' # array with 2 elements
367 new P1, 'Iterator', P2
370 eq I0, I1, ok2 # iter.length() == array.length()
373 new P1, 'Iterator', P0
374 set P1, .ITERATE_FROM_START
376 unless P1, ok4 # if(iter) == false on empty
379 new P1, 'Iterator', P2
380 set P1, .ITERATE_FROM_START
381 if P1, ok5 # if(iter) == true on non empty
384 # now iterate over P2
385 # while (P1) { element = shift(P1) }
396 unless P1, ok8 # if(iter) == false after last
400 # now iterate from end
401 set P1, .ITERATE_FROM_END
402 if P1, ok9 # if(iter) == true on non empty
405 # while (P1) { element = pop(P1) }
410 ok10: print "ok 10\n"
415 ok11: print "ok 11\n"
416 unless P1, ok12 # if(iter) == false after last
418 ok12: print "ok 12\n"
436 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
442 does bool1, pmc1, "scalar"
445 does bool1, pmc1, "array"
448 does bool1, pmc1, "no_interface"
459 pasm_output_is( << "CODE", << 'OUTPUT', "Access via Key PMC" );
460 @{[ $fp_equality_macro ]}
467 set P31["Test"], "ok"
478 .fp_eq(N0, 12.298, ok2)
502 pasm_output_is( << 'CODE', << 'OUTPUT', "Store PMC, get int" );
525 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store num, get int" );
533 /SArray: Entry not an integer!/
536 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store string, get int" );
539 set P0[0], "Non-numeric string"
544 /SArray: Entry not an integer!/
547 pasm_output_is( << "CODE", << 'OUTPUT', "Store PMC, get num" );
548 @{[ $fp_equality_macro ]}
558 .fp_eq(N0, 11.0, ok1)
571 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store int, get num" );
579 /SArray: Entry not a number!/
582 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store string, get num" );
585 set P0[0], "Non-numeric string"
590 /SArray: Entry not a number!/
593 pasm_output_is( << 'CODE', << 'OUTPUT', "Store PMC, get string" );
616 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store int, get string" );
624 /SArray: Entry not a string!/
627 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Store num, get string" );
635 /SArray: Entry not a string!/
638 pasm_output_is( << "CODE", << 'OUTPUT', "Store num, get PMC" );
639 @{[ $fp_equality_macro ]}
647 .fp_eq(N0, 12.239, ok1)
653 .fp_eq(N0, -1.9742, ok2)
662 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: int" );
670 /SArray index out of bounds/
673 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: num" );
681 /SArray index out of bounds/
684 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: string" );
692 /SArray index out of bounds/
695 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: push int" );
702 /SArray index out of bounds/
705 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: push num" );
712 /SArray index out of bounds/
715 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: push string" );
722 /SArray index out of bounds/
725 pasm_error_output_like( << 'CODE', << 'OUTPUT', "Out-of-bounds access: push pmc" );
734 /SArray index out of bounds/
739 # cperl-indent-level: 4
742 # vim: expandtab shiftwidth=4: