2 # Copyright (C) 2001-2008, Parrot Foundation.
7 use lib qw( t . lib ../lib ../../lib );
10 use Parrot::Test tests => 26;
14 t/library/dumper.t - test dumping of data
18 % prove t/library/dumper.t
27 pir_output_is( <<'CODE', <<'OUT', "dumping array of sorted numbers" );
30 load_bytecode "dumper.pbc"
33 new array, 'ResizablePMCArray'
45 _dumper( array, "array" )
48 "array" => ResizablePMCArray (size:10) [
64 pir_output_is( <<'CODE', <<'OUT', "dumping unsorted numbers" );
66 load_bytecode "dumper.pbc"
69 new array, 'ResizablePMCArray'
81 _dumper( array, "array" )
84 "array" => ResizablePMCArray (size:10) [
99 pir_output_is( <<'CODE', <<'OUT', "dumping sorted strings" );
102 load_bytecode "dumper.pbc"
105 new array, 'ResizablePMCArray'
108 push array, "charlie"
111 push array, "foxtrot"
115 _dumper( array, "strings" )
118 "strings" => ResizablePMCArray (size:8) [
131 pir_output_is( <<'CODE', <<'OUT', "sorting unsorted strings" );
134 load_bytecode "dumper.pbc"
137 new array, 'ResizablePMCArray'
138 push array, "charlie"
142 push array, "foxtrot"
147 _dumper( array, "strings" )
150 "strings" => ResizablePMCArray (size:8) [
163 pir_output_is( <<'CODE', <<'OUT', "dumping different types" );
166 load_bytecode "dumper.pbc"
169 new array, 'ResizablePMCArray'
171 push array, "charlie"
179 push array, "foxtrot"
191 _dumper( array, "array" )
194 "array" => ResizablePMCArray (size:20) [
219 pir_output_is( <<'CODE', <<'OUT', "dumping complex data" );
222 load_bytecode "dumper.pbc"
232 new array1, 'ResizablePMCArray'
233 new array2, 'ResizablePMCArray'
235 _dumper( hash1,"hash1" )
241 _dumper( hash1,"hash1" )
247 _dumper( hash1,"hash1" )
250 set hash1[$S0], hash2
252 _dumper( hash1,"hash1" )
258 _dumper( hash1,"hash1" )
274 set hash2[$S0], array1
276 _dumper( hash1,"hash1" )
304 "array1" => ResizablePMCArray (size:5) [
322 pir_output_is( <<'CODE', <<'OUT', "properties" );
325 load_bytecode "dumper.pbc"
329 new array, 'ResizablePMCArray'
335 setprop array, "key1", str
339 setprop array, "key2", str
345 "VAR1" => ResizablePMCArray (size:2) [
348 ] with-properties: Hash {
355 pir_output_is( <<'CODE', <<'OUT', "indent string" );
358 load_bytecode "dumper.pbc"
368 new array1, 'ResizablePMCArray'
369 new array2, 'ResizablePMCArray'
371 set hash1["hash2"], hash2
372 set hash2["array"], array1
373 set hash1["test1"], "test1"
374 set hash2["test2"], "test2"
378 setprop hash1, "array2", array2
381 _dumper( hash1, name, indent )
382 _dumper( hash1, name, indent )
385 print "'\nindent = '"
392 | | "array" => ResizablePMCArray (size:2) [
394 | | | ResizablePMCArray (size:1) [
398 | | "test2" => "test2"
401 } with-properties: Hash {
402 | "array2" => \hash["hash2"]["array"][1]
406 | | "array" => ResizablePMCArray (size:2) [
408 | | | ResizablePMCArray (size:1) [
412 | | "test2" => "test2"
415 } with-properties: Hash {
416 | "array2" => \hash["hash2"]["array"][1]
423 pir_output_is( <<'CODE', <<'OUT', "back-referencing properties" );
426 load_bytecode "dumper.pbc"
431 set hash["hello"], "world"
432 setprop hash, "backref", hash
438 } with-properties: Hash {
444 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (1)" );
447 load_bytecode "dumper.pbc"
453 set hash["hello"], "world"
454 setprop hash, "self", hash
456 setprop hash, "self", prop
462 } with-properties: Hash {
463 "self" => \VAR1.properties()
468 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (2)" );
471 load_bytecode "dumper.pbc"
477 new array, 'ResizablePMCArray'
481 set hash1["hello1"], "world1"
482 set hash2["hello2"], "world2"
483 setprop hash1, "das leben", hash2
485 set prop["das leben"], "ist schoen"
486 setprop hash2, "hash1prop", prop
495 "VAR1" => ResizablePMCArray (size:4) [
498 } with-properties: Hash {
499 "das leben" => "ist schoen"
503 } with-properties: Hash {
504 "hash1prop" => \VAR1[0].properties()
506 \VAR1[0].properties(),
507 \VAR1[1].properties()
512 pir_output_is( <<'CODE', <<'OUT', "dumping objects" );
515 load_bytecode "dumper.pbc"
519 newclass temp, "TestClass"
521 new array, 'ResizablePMCArray'
522 temp = new "TestClass"
524 $P0 = get_class 'TestClass'
531 .namespace ["TestClass"]
536 .local string subindent
540 (subindent, indent) = dumper."newIndent"()
555 dumper."deleteIndent"()
562 "VAR1" => ResizablePMCArray (size:2) [
575 pir_output_is( <<'CODE', <<'OUT', "dumping 'null'" );
578 load_bytecode "dumper.pbc"
582 new array, 'ResizablePMCArray'
598 _dumper( array, "array" )
601 "array" => ResizablePMCArray (size:5) [
611 pir_output_is( << 'CODE', << 'OUT', "dumping strings" );
614 load_bytecode "dumper.pbc"
616 array = new 'ResizablePMCArray'
618 .local pmc pmc_string, pmc_perl_string
619 .local string string_1
621 pmc_string = new 'String'
622 pmc_string = "This is a String PMC"
623 push array, pmc_string
625 pmc_perl_string = new 'String'
626 pmc_perl_string = "This is a String PMC"
627 push array, pmc_perl_string
629 string_1 = "This is a String"
632 _dumper( array, "array of various strings" )
635 "array of various strings" => ResizablePMCArray (size:3) [
636 "This is a String PMC",
637 "This is a String PMC",
643 pir_output_is( <<'CODE', <<'OUT', "dumping complex data in Hash" );
646 load_bytecode "dumper.pbc"
655 new array1, 'ResizablePMCArray'
657 _dumper( hash1,"hash1" )
663 _dumper( hash1,"hash1" )
669 _dumper( hash1,"hash1" )
672 set hash1[$S0], hash2
674 _dumper( hash1,"hash1" )
680 _dumper( hash1,"hash1" )
697 set hash2[$S0], array1
699 _dumper( hash1,"hash1" )
727 "array1" => ResizablePMCArray (size:5) [
745 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Integer PMC" );
748 load_bytecode "dumper.pbc"
753 _dumper( int1, "Int:" )
760 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Float PMC" );
763 load_bytecode "dumper.pbc"
768 _dumper( float1, "Float:" )
771 "Float:" => 12345.678
775 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizablePMCArray PMC" );
777 load_bytecode "dumper.pbc"
780 new array, 'ResizablePMCArray'
783 _dumper( array, "array:" )
786 "array:" => ResizablePMCArray (size:2) [
793 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableStringArray PMC" );
795 load_bytecode "dumper.pbc"
798 new array, 'ResizableStringArray'
801 _dumper( array, "array:" )
804 "array:" => ResizableStringArray (size:2) [
811 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableIntegerArray PMC" );
813 load_bytecode "dumper.pbc"
816 new array, 'ResizableIntegerArray'
819 _dumper( array, "array:" )
822 "array:" => ResizableIntegerArray (size:2) [
829 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableFloatArray PMC" );
831 load_bytecode "dumper.pbc"
834 new array, 'ResizableFloatArray'
837 _dumper( array, "array:" )
840 "array:" => ResizableFloatArray (size:2) [
847 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedPMCArray PMC" );
849 load_bytecode "dumper.pbc"
852 new array, 'FixedPMCArray'
856 _dumper( array, "array:" )
859 "array:" => FixedPMCArray (size:2) [
866 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedStringArray PMC" );
868 load_bytecode "dumper.pbc"
871 new array, 'FixedStringArray'
875 _dumper( array, "array:" )
878 "array:" => FixedStringArray (size:2) [
885 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedIntegerArray PMC" );
887 load_bytecode "dumper.pbc"
890 new array, 'FixedIntegerArray'
894 _dumper( array, "array:" )
897 "array:" => FixedIntegerArray (size:2) [
904 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedFloatArray PMC" );
906 load_bytecode "dumper.pbc"
909 new array, 'FixedFloatArray'
913 _dumper( array, "array:" )
916 "array:" => FixedFloatArray (size:2) [
922 # no. 26 - Deleted --leo
925 pir_output_is( <<'CODE', <<'OUTPUT', "custom dumper" );
927 load_bytecode "dumper.pbc"
929 cl = subclass 'ResizablePMCArray', 'bar'
935 .sub init :vtable :method
937 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
945 print " __value => {\n"
947 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
948 dumper.'dump'('attr', ar)
954 "VAR1" => PMC 'bar' __value => {
955 ResizablePMCArray (size:2) [
962 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping IntegerArray PMC");
963 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping FloatValArray PMC");
967 # cperl-indent-level: 4
970 # vim: expandtab shiftwidth=4: