X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=dev%2Fi386%2Flibpod-simple-perl%2Flibpod-simple-perl-3.07%2Ft%2Fstree.t;fp=dev%2Fi386%2Flibpod-simple-perl%2Flibpod-simple-perl-3.07%2Ft%2Fstree.t;h=efdf8097fafead3efe94bfe3c5b876ce769c6d18;hb=8977e561d8a9eae6959218b0306c9df2056a38a9;hp=0000000000000000000000000000000000000000;hpb=df794b845212301ea0d267c919232538bfef356a;p=dh-make-perl diff --git a/dev/i386/libpod-simple-perl/libpod-simple-perl-3.07/t/stree.t b/dev/i386/libpod-simple-perl/libpod-simple-perl-3.07/t/stree.t new file mode 100644 index 0000000..efdf809 --- /dev/null +++ b/dev/i386/libpod-simple-perl/libpod-simple-perl-3.07/t/stree.t @@ -0,0 +1,151 @@ + + +use strict; +use Test; +BEGIN { plan tests => 33 }; + +#use Pod::Simple::Debug (6); + +ok 1; + +use Pod::Simple::SimpleTree; +print "# Pod::Simple version $Pod::Simple::VERSION\n"; + +my $hashes_dont_matter = 0; + + +my $x = 'Pod::Simple::SimpleTree'; +sub x { + my $p = $x->new; + $p->merge_text(1); + $p->parse_string_document( shift )->root; +} + +ok 1; + +print "# a bit of meta-testing...\n"; +&ok( deq( 1, 1 )); +&ok(!deq( 2, 1 )); + +&ok( deq( undef, undef )); +&ok(!deq( undef, 1 )); +&ok(!deq( 1, undef )); + +&ok( deq( [ ], [ ] )); +&ok(!deq( [ ], 1 )); +&ok(!deq( 1, [ ] )); + +&ok( deq( [1], [1] )); +&ok(!deq( [1], 1 )); +&ok(!deq( 1, [1] )); +&ok(!deq( [1], [ ] )); +&ok(!deq( [ ], [1] )); +&ok(!deq( [1], [2] )); +&ok(!deq( [2], [1] )); + +&ok( deq( [ ], [ ] )); +&ok(!deq( [ ], 1 )); +&ok(!deq( 1, [ ] )); + +&ok( deq( {}, {} )); +&ok(!deq( {}, 1 )); +&ok(!deq( 1, {} )); +&ok(!deq( {1,2}, {} )); +&ok(!deq( {}, {1,2} )); +&ok( deq( {1,2}, {1,2} )); +&ok(!deq( {2,1}, {1,2} )); + + + + +print '# ', Pod::Simple::pretty(x( "=pod\n\nI like pie.\n" )), "\n"; +print "# Making sure we get a tree at all...\n"; +ok x( "=pod\n\nI like pie.\n" ); + + +print "# Some real tests...\n"; +&ok( deq( x( "=pod\n\nI like pie.\n"), + [ "Document", {"start_line"=>1}, + [ "Para", {"start_line"=>3}, + "I like pie." + ] + ] +)); + +$hashes_dont_matter = 1; + +&ok( deq( x("=pod\n\nB\n"), + [ "Document", {}, + [ "Para", {}, + ["B", {}, + "foo " + ] + ] + ] +)); + + +&ok( deq( x("=pod\n\nBXI>\n"), + [ "Document", {}, + [ "Para", {}, + ["B", {}, + "pie", + ['F',{}, 'zorch'], + ['X',{}, 'foo' ], + ['I',{}, 'pling'], + ] + ] + ] +)); + +&ok( deq( x("=over\n\n=item BXI>!\n\n=back"), + [ "Document", {}, + [ "over-text", {}, + [ "item-text", {}, + ["B", {}, + "pie", + ['F',{}, 'zorch'], + ['X',{}, 'foo' ], + ['I',{}, 'pling'], + ], + '!' + ] + ] + ] +)); + +print "# Wrapping up... one for the road...\n"; +ok 1; +print "# --- Done with ", __FILE__, " --- \n"; + +sub deq { # deep-equals + #print "# deq ", Pod::Simple::pretty($_[0], $_[1]), "\n"; + return 1 unless defined $_[0] or defined $_[1]; # two undefs = same + return '' if defined $_[0] xor defined $_[1]; + return '' if ref($_[0]) ne ref($_[1]); # unequal referentiality + return $_[0] eq $_[1] unless ref $_[0]; + # So it's a ref: + use UNIVERSAL; + if(UNIVERSAL::isa($_[0], 'ARRAY')) { + return '' unless @{$_[0]} == @{$_[1]}; + for(my $i = 0; $i < @{$_[0]}; $i++) { + print("# NEQ ", Pod::Simple::pretty($_[0]), + "\n# != ", Pod::Simple::pretty($_[1]), "\n"), + return '' unless deq($_[0][$i], $_[1][$i]); # recurse! + } + return 1; + } elsif(UNIVERSAL::isa($_[0], 'HASH')) { + return 1 if $hashes_dont_matter; + return '' unless keys %{$_[0]} == keys %{$_[1]}; + foreach my $k (keys %{$_[0]}) { + return '' unless exists $_[1]{$k}; + return '' unless deq($_[0]{$k}, $_[1]{$k}); + } + return 1; + } else { + print "# I don't know how to deque $_[0] & $_[1]\n"; + return 1; + } +} + +