2 # Copyright (C) 2008, Parrot Foundation.
10 use Parrot::Test tests => 26;
14 t/library/yaml_dumper.t - test dumping of data in YAML format
18 % prove t/library/yaml_dumper.t
22 Tests data dumping in YAML format.
27 pir_output_is( <<'CODE', <<'OUT', "dumping array of sorted numbers" );
30 load_bytecode "yaml_dumper.pbc"
33 new array, 'ResizablePMCArray'
45 yaml( array, "array" )
50 "array" : !ResizablePMCArray [
66 pir_output_is( <<'CODE', <<'OUT', "dumping unsorted numbers" );
68 load_bytecode "yaml_dumper.pbc"
71 new array, 'ResizablePMCArray'
83 yaml( array, "array" )
88 "array" : !ResizablePMCArray [
104 pir_output_is( <<'CODE', <<'OUT', "dumping sorted strings" );
107 load_bytecode "yaml_dumper.pbc"
110 new array, 'ResizablePMCArray'
113 push array, "charlie"
116 push array, "foxtrot"
120 yaml( array, "strings" )
125 "strings" : !ResizablePMCArray [
128 !String [ "charlie" ],
131 !String [ "foxtrot" ],
139 pir_output_is( <<'CODE', <<'OUT', "sorting unsorted strings" );
142 load_bytecode "yaml_dumper.pbc"
145 new array, 'ResizablePMCArray'
146 push array, "charlie"
150 push array, "foxtrot"
155 yaml( array, "strings" )
160 "strings" : !ResizablePMCArray [
161 !String [ "charlie" ],
165 !String [ "foxtrot" ],
174 pir_output_is( <<'CODE', <<'OUT', "dumping different types" );
177 load_bytecode "yaml_dumper.pbc"
180 new array, 'ResizablePMCArray'
182 push array, "charlie"
190 push array, "foxtrot"
202 yaml( array, "array" )
207 "array" : !ResizablePMCArray [
209 !String [ "charlie" ],
217 !String [ "foxtrot" ],
233 pir_output_is( <<'CODE', <<'OUT', "dumping complex data" );
236 load_bytecode "yaml_dumper.pbc"
246 new array1, 'ResizablePMCArray'
247 new array2, 'ResizablePMCArray'
249 yaml( hash1,"hash1" )
255 yaml( hash1,"hash1" )
261 yaml( hash1,"hash1" )
264 set hash1[$S0], hash2
266 yaml( hash1,"hash1" )
272 yaml( hash1,"hash1" )
288 set hash2[$S0], array1
290 yaml( hash1,"hash1" )
302 "hello" : !String [ "world" ],
308 "hello" : !String [ "world" ],
309 "hello2" : !String [ "world2" ],
317 "hello" : !String [ "world" ],
318 "hello2" : !String [ "world2" ],
325 "hello3" : !String [ "world3" ],
327 "hello" : !String [ "world" ],
328 "hello2" : !String [ "world2" ],
335 "array1" : !ResizablePMCArray [
341 "is" : !String [ "cool" ],
342 "name" : !String [ "parrot" ],
345 "hello3" : !String [ "world3" ],
347 "hello" : !String [ "world" ],
348 "hello2" : !String [ "world2" ],
354 pir_output_is( <<'CODE', <<'OUT', "properties", todo => 'not yet implemented' );
357 load_bytecode "yaml_dumper.pbc"
361 new array, 'ResizablePMCArray'
367 setprop array, "key1", str
371 setprop array, "key2", str
379 "VAR1" : !ResizablePMCArray [
380 !"key1" : !String [ "value1" ],
381 !"key2" : !String [ "value2" ],
389 pir_output_is( <<'CODE', <<'OUT', "indent string", todo => 'not supported' );
392 load_bytecode "yaml_dumper.pbc"
402 new array1, 'ResizablePMCArray'
403 new array2, 'ResizablePMCArray'
405 set hash1["hash2"], hash2
406 set hash2["array"], array1
407 set hash1["test1"], "test1"
408 set hash2["test2"], "test2"
412 setprop hash1, "array2", array2
415 yaml( hash1, name, indent )
416 yaml( hash1, name, indent )
419 print "'\nindent = '"
426 | | "array" : ResizablePMCArray (size:2) [
428 | | | ResizablePMCArray (size:1) [
432 | | "test2" : "test2"
435 } with-properties: Hash {
436 | "array2" : \hash["hash2"]["array"][1]
440 | | "array" : ResizablePMCArray (size:2) [
442 | | | ResizablePMCArray (size:1) [
446 | | "test2" : "test2"
449 } with-properties: Hash {
450 | "array2" : \hash["hash2"]["array"][1]
457 pir_output_is( <<'CODE', <<'OUT', "back-referencing properties", todo => 'not yet implemented' );
460 load_bytecode "yaml_dumper.pbc"
465 set hash["hello"], "world"
466 setprop hash, "backref", hash
472 } with-properties: Hash {
478 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (1)", todo => 'not yet implemented' );
481 load_bytecode "yaml_dumper.pbc"
487 set hash["hello"], "world"
488 setprop hash, "self", hash
490 setprop hash, "self", prop
496 } with-properties: Hash {
497 "self" : \VAR1.properties()
502 pir_output_is( <<'CODE', <<'OUT', "self-referential properties (2)", todo => 'not yet implemented' );
505 load_bytecode "yaml_dumper.pbc"
511 new array, 'ResizablePMCArray'
515 set hash1["hello1"], "world1"
516 set hash2["hello2"], "world2"
517 setprop hash1, "das leben", hash2
519 set prop["das leben"], "ist schoen"
520 setprop hash2, "hash1prop", prop
529 "VAR1" : ResizablePMCArray (size:4) [
532 } with-properties: Hash {
533 "das leben" : "ist schoen"
537 } with-properties: Hash {
538 "hash1prop" : \VAR1[0].properties()
540 \VAR1[0].properties(),
541 \VAR1[1].properties()
546 pir_output_is( <<'CODE', <<'OUT', "dumping objects" );
549 load_bytecode "yaml_dumper.pbc"
553 newclass temp, "TestClass"
555 new array, 'ResizablePMCArray'
556 temp = new "TestClass"
558 $P0 = get_class 'TestClass'
565 .namespace ["TestClass"]
570 .local string subindent
574 (subindent, indent) = dumper."newIndent"()
589 dumper."deleteIndent"()
598 "VAR1" : !ResizablePMCArray [
612 pir_output_is( <<'CODE', <<'OUT', "dumping 'null'" );
615 load_bytecode "yaml_dumper.pbc"
619 new array, 'ResizablePMCArray'
635 yaml( array, "array" )
640 "array" : !ResizablePMCArray [
651 pir_output_is( << 'CODE', << 'OUT', "dumping strings" );
654 load_bytecode "yaml_dumper.pbc"
656 array = new 'ResizablePMCArray'
658 .local pmc pmc_string, pmc_perl_string
659 .local string string_1
661 pmc_string = new 'String'
662 pmc_string = "This is a String PMC"
663 push array, pmc_string
665 pmc_perl_string = new 'String'
666 pmc_perl_string = "This is a String PMC"
667 push array, pmc_perl_string
669 string_1 = "This is a String"
672 yaml( array, "array of various strings" )
677 "array of various strings" : !ResizablePMCArray [
678 !String [ "This is a String PMC" ],
679 !String [ "This is a String PMC" ],
680 !String [ "This is a String" ],
686 pir_output_is( <<'CODE', <<'OUT', "dumping complex data in Hash" );
689 load_bytecode "yaml_dumper.pbc"
698 new array1, 'ResizablePMCArray'
700 yaml( hash1,"hash1" )
706 yaml( hash1,"hash1" )
712 yaml( hash1,"hash1" )
715 set hash1[$S0], hash2
717 yaml( hash1,"hash1" )
723 yaml( hash1,"hash1" )
740 set hash2[$S0], array1
742 yaml( hash1,"hash1" )
754 "hello" : !String [ "world" ],
760 "hello" : !String [ "world" ],
761 "hello2" : !String [ "world2" ],
769 "hello" : !String [ "world" ],
770 "hello2" : !String [ "world2" ],
777 "hello3" : !String [ "world3" ],
779 "hello" : !String [ "world" ],
780 "hello2" : !String [ "world2" ],
787 "array1" : !ResizablePMCArray [
793 "is" : !String [ "cool" ],
794 "name" : !String [ "parrot" ],
797 "hello3" : !String [ "world3" ],
799 "hello" : !String [ "world" ],
800 "hello2" : !String [ "world2" ],
806 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Integer PMC" );
809 load_bytecode "yaml_dumper.pbc"
819 "Int" : !Integer [ 12345 ],
824 pir_output_is( <<'CODE', <<'OUTPUT', "dumping Float PMC" );
827 load_bytecode "yaml_dumper.pbc"
832 yaml( float1, "Float" )
837 "Float" : !Float [ 12345.678 ],
843 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizablePMCArray PMC" );
845 load_bytecode "yaml_dumper.pbc"
848 new array, 'ResizablePMCArray'
851 yaml( array, "array" )
856 "array" : !ResizablePMCArray [
864 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableStringArray PMC" );
866 load_bytecode "yaml_dumper.pbc"
869 new array, 'ResizableStringArray'
872 yaml( array, "array:" )
877 "array:" : !ResizableStringArray [
885 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableIntegerArray PMC" );
887 load_bytecode "yaml_dumper.pbc"
890 new array, 'ResizableIntegerArray'
893 yaml( array, "array:" )
898 "array:" : !ResizableIntegerArray [
906 pir_output_is( <<'CODE', <<'OUTPUT', "dumping ResizableFloatArray PMC" );
908 load_bytecode "yaml_dumper.pbc"
911 new array, 'ResizableFloatArray'
914 yaml( array, "array:" )
919 "array:" : !ResizableFloatArray [
927 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedPMCArray PMC" );
929 load_bytecode "yaml_dumper.pbc"
932 new array, 'FixedPMCArray'
936 yaml( array, "array:" )
941 "array:" : !FixedPMCArray [
949 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedStringArray PMC" );
951 load_bytecode "yaml_dumper.pbc"
954 new array, 'FixedStringArray'
958 yaml( array, "array:" )
963 "array:" : !FixedStringArray [
971 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedIntegerArray PMC" );
973 load_bytecode "yaml_dumper.pbc"
976 new array, 'FixedIntegerArray'
980 yaml( array, "array:" )
985 "array:" : !FixedIntegerArray [
993 pir_output_is( <<'CODE', <<'OUTPUT', "dumping FixedFloatArray PMC" );
995 load_bytecode "yaml_dumper.pbc"
998 new array, 'FixedFloatArray'
1002 yaml( array, "array:" )
1007 "array:" : !FixedFloatArray [
1015 pir_output_is( <<'CODE', <<'OUTPUT', "custom dumper", todo => 'not yet implemented');
1017 load_bytecode "yaml_dumper.pbc"
1019 cl = subclass 'ResizablePMCArray', 'bar'
1025 .sub init :vtable :method
1027 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
1037 ar = getattribute self, ['ResizablePMCArray'], 'proxy'
1038 dumper.'yaml'('attr', ar)
1047 !ResizablePMCArray [
1055 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping IntegerArray PMC");
1056 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping FloatValArray PMC");
1060 # cperl-indent-level: 4
1063 # vim: expandtab shiftwidth=4: