2 # Copyright (C) 2001-2006, The Perl 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" );
29 .include "library/dumper.pir"
33 new array, 'ResizablePMCArray'
45 _dumper( array, "array" )
48 "array" => ResizablePMCArray (size:10) [
64 pir_output_is( <<'CODE', <<'OUT', "dumping unsorted numbers" );
65 .include "library/dumper.pir"
69 new array, 'ResizablePMCArray'
81 _dumper( array, "array" )
84 "array" => ResizablePMCArray (size:10) [
99 pir_output_is( <<'CODE', <<'OUT', "dumping sorted strings" );
101 .include "library/dumper.pir"
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" );
136 new array, 'ResizablePMCArray'
137 push array, "charlie"
141 push array, "foxtrot"
146 _dumper( array, "strings" )
148 .include "library/dumper.pir"
150 "strings" => ResizablePMCArray (size:8) [
163 pir_output_is( <<'CODE', <<'OUT', "dumping different types" );
168 new array, 'ResizablePMCArray'
170 push array, "charlie"
178 push array, "foxtrot"
190 _dumper( array, "array" )
192 .include "library/dumper.pir"
194 "array" => ResizablePMCArray (size:20) [
219 pir_output_is( <<'CODE', <<'OUT', "dumping complex data" );
231 new array1, 'ResizablePMCArray'
232 new array2, 'ResizablePMCArray'
234 _dumper( hash1,"hash1" )
240 _dumper( hash1,"hash1" )
246 _dumper( hash1,"hash1" )
251 _dumper( hash1,"hash1" )
257 _dumper( hash1,"hash1" )
273 set hash2[S0], array1
275 _dumper( hash1,"hash1" )
278 .include "library/dumper.pir"
304 "array1" => ResizablePMCArray (size:5) [
322 pir_output_is( <<'CODE', <<'OUT', "properties" );
328 new array, 'ResizablePMCArray'
334 setprop array, "key1", str
338 setprop array, "key2", str
343 .include "library/dumper.pir"
345 "VAR1" => ResizablePMCArray (size:2) [
348 ] with-properties: Hash {
355 pir_output_is( <<'CODE', <<'OUT', "indent string" );
367 new array1, 'ResizablePMCArray'
368 new array2, 'ResizablePMCArray'
370 set hash1["hash2"], hash2
371 set hash2["array"], array1
372 set hash1["test1"], "test1"
373 set hash2["test2"], "test2"
377 setprop hash1, "array2", array2
380 _dumper( hash1, name, indent )
381 _dumper( hash1, name, indent )
384 print "'\nindent = '"
388 .include "library/dumper.pir"
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" );
430 set hash["hello"], "world"
431 setprop hash, "backref", hash
434 .include "library/dumper.pir"
438 } with-properties: Hash {
444 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (1)" );
452 set hash["hello"], "world"
453 setprop hash, "self", hash
455 setprop hash, "self", prop
458 .include "library/dumper.pir"
462 } with-properties: Hash {
463 "self" => \VAR1.properties()
468 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (2)" );
476 new array, 'ResizablePMCArray'
480 set hash1["hello1"], "world1"
481 set hash2["hello2"], "world2"
482 setprop hash1, "das leben", hash2
484 set prop["das leben"], "ist schoen"
485 setprop hash2, "hash1prop", prop
493 .include "library/dumper.pir"
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" );
518 newclass temp, "TestClass"
520 new array, 'ResizablePMCArray'
521 temp = new "TestClass"
523 $P0 = get_class 'TestClass'
530 .namespace ["TestClass"]
535 .local string subindent
539 (subindent, indent) = dumper."newIndent"()
554 dumper."deleteIndent"()
560 .include "library/dumper.pir"
562 "VAR1" => ResizablePMCArray (size:2) [
575 pir_output_is( <<'CODE', <<'OUT', "dumping 'null'" );
581 new array, 'ResizablePMCArray'
597 _dumper( array, "array" )
599 .include "library/dumper.pir"
601 "array" => ResizablePMCArray (size:5) [
611 pir_output_is( << 'CODE', << 'OUT', "dumping strings" );
613 .include "library/dumper.pir"
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" );
654 new array1, 'ResizablePMCArray'
656 _dumper( hash1,"hash1" )
662 _dumper( hash1,"hash1" )
668 _dumper( hash1,"hash1" )
673 _dumper( hash1,"hash1" )
679 _dumper( hash1,"hash1" )
696 set hash2[S0], array1
698 _dumper( hash1,"hash1" )
701 .include "library/dumper.pir"
727 "array1" => ResizablePMCArray (size:5) [
745 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Integer PMC" );
752 _dumper( int1, "Int:" )
754 .include "library/dumper.pir"
760 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Float PMC" );
767 _dumper( float1, "Float:" )
769 .include "library/dumper.pir"
775 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizablePMCArray PMC" );
779 new array, 'ResizablePMCArray'
782 _dumper( array, "array:" )
784 .include "library/dumper.pir"
786 "array:" => ResizablePMCArray (size:2) [
793 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableStringArray PMC" );
797 new array, 'ResizableStringArray'
800 _dumper( array, "array:" )
802 .include "library/dumper.pir"
804 "array:" => ResizableStringArray (size:2) [
811 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableIntegerArray PMC" );
815 new array, 'ResizableIntegerArray'
818 _dumper( array, "array:" )
820 .include "library/dumper.pir"
822 "array:" => ResizableIntegerArray (size:2) [
829 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableFloatArray PMC" );
833 new array, 'ResizableFloatArray'
836 _dumper( array, "array:" )
838 .include "library/dumper.pir"
840 "array:" => ResizableFloatArray (size:2) [
847 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedPMCArray PMC" );
851 new array, 'FixedPMCArray'
855 _dumper( array, "array:" )
857 .include "library/dumper.pir"
859 "array:" => FixedPMCArray (size:2) [
866 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedStringArray PMC" );
870 new array, 'FixedStringArray'
874 _dumper( array, "array:" )
876 .include "library/dumper.pir"
878 "array:" => FixedStringArray (size:2) [
885 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedIntegerArray PMC" );
889 new array, 'FixedIntegerArray'
893 _dumper( array, "array:" )
895 .include "library/dumper.pir"
897 "array:" => FixedIntegerArray (size:2) [
904 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedFloatArray PMC" );
908 new array, 'FixedFloatArray'
912 _dumper( array, "array:" )
914 .include "library/dumper.pir"
916 "array:" => FixedFloatArray (size:2) [
922 # no. 26 - Deleted --leo
925 pir_output_is( <<'CODE', <<'OUTPUT', "custom dumper" );
928 cl = subclass 'ResizablePMCArray', 'bar'
934 .sub init :vtable :method
936 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
944 print " __value => {\n"
946 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
947 dumper.'dump'('attr', ar)
951 .include 'library/dumper.pir'
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: