5 BEGIN { plan tests => 33 };
7 #use Pod::Simple::Debug (6);
11 use Pod::Simple::SimpleTree;
12 print "# Pod::Simple version $Pod::Simple::VERSION\n";
14 my $hashes_dont_matter = 0;
17 my $x = 'Pod::Simple::SimpleTree';
21 $p->parse_string_document( shift )->root;
26 print "# a bit of meta-testing...\n";
30 &ok( deq( undef, undef ));
31 &ok(!deq( undef, 1 ));
32 &ok(!deq( 1, undef ));
34 &ok( deq( [ ], [ ] ));
38 &ok( deq( [1], [1] ));
41 &ok(!deq( [1], [ ] ));
42 &ok(!deq( [ ], [1] ));
43 &ok(!deq( [1], [2] ));
44 &ok(!deq( [2], [1] ));
46 &ok( deq( [ ], [ ] ));
53 &ok(!deq( {1,2}, {} ));
54 &ok(!deq( {}, {1,2} ));
55 &ok( deq( {1,2}, {1,2} ));
56 &ok(!deq( {2,1}, {1,2} ));
61 print '# ', Pod::Simple::pretty(x( "=pod\n\nI like pie.\n" )), "\n";
62 print "# Making sure we get a tree at all...\n";
63 ok x( "=pod\n\nI like pie.\n" );
66 print "# Some real tests...\n";
67 &ok( deq( x( "=pod\n\nI like pie.\n"),
68 [ "Document", {"start_line"=>1},
69 [ "Para", {"start_line"=>3},
75 $hashes_dont_matter = 1;
77 &ok( deq( x("=pod\n\nB<foo\t>\n"),
88 &ok( deq( x("=pod\n\nB<pieF<zorch>X<foo>I<pling>>\n"),
101 &ok( deq( x("=over\n\n=item B<pieF<zorch>X<foo>I<pling>>!\n\n=back"),
117 print "# Wrapping up... one for the road...\n";
119 print "# --- Done with ", __FILE__, " --- \n";
121 sub deq { # deep-equals
122 #print "# deq ", Pod::Simple::pretty($_[0], $_[1]), "\n";
123 return 1 unless defined $_[0] or defined $_[1]; # two undefs = same
124 return '' if defined $_[0] xor defined $_[1];
125 return '' if ref($_[0]) ne ref($_[1]); # unequal referentiality
126 return $_[0] eq $_[1] unless ref $_[0];
128 if(UNIVERSAL::isa($_[0], 'ARRAY')) {
129 return '' unless @{$_[0]} == @{$_[1]};
130 for(my $i = 0; $i < @{$_[0]}; $i++) {
131 print("# NEQ ", Pod::Simple::pretty($_[0]),
132 "\n# != ", Pod::Simple::pretty($_[1]), "\n"),
133 return '' unless deq($_[0][$i], $_[1][$i]); # recurse!
136 } elsif(UNIVERSAL::isa($_[0], 'HASH')) {
137 return 1 if $hashes_dont_matter;
138 return '' unless keys %{$_[0]} == keys %{$_[1]};
139 foreach my $k (keys %{$_[0]}) {
140 return '' unless exists $_[1]{$k};
141 return '' unless deq($_[0]{$k}, $_[1]{$k});
145 print "# I don't know how to deque $_[0] & $_[1]\n";