# ---------------------------------------------------------------- use strict; use Test::More tests => 25; BEGIN { use_ok('XML::TreePP') }; # ---------------------------------------------------------------- { my $tpp = XML::TreePP->new( force_array => [qw( one two three )] ); my $source = <<"EOT"; AAA CCC DDDEEE EOT my $tree = $tpp->parse( $source ); ok( ! ref $tree->{root}->{zero}, "A: normal node" ); ok( ref $tree->{root}->{one} , "A: one force_array node" ); ok( ref $tree->{root}->{two} , "A: two child nodes" ); ok( ref $tree->{root}->{three} , "A: three empty nodes" ); is( scalar( @{$tree->{root}->{one}} ), 1, "A: one force_array node" ); is( scalar( @{$tree->{root}->{two}} ), 2, "A: two child nodes" ); is( scalar( @{$tree->{root}->{three}} ), 3, "A: three empty nodes" ); is( scalar( grep {$_} @{$tree->{root}->{one}} ), 1, "A: one force_array node" ); is( scalar( grep {$_} @{$tree->{root}->{two}} ), 2, "A: two child nodes" ); is( scalar( grep {$_} @{$tree->{root}->{three}} ), 0, "A: three empty nodes" ); } # ---------------------------------------------------------------- { my $tpp = XML::TreePP->new( force_array => [qw( one two three )] ); my $source = <<"EOT"; EOT my $tree = $tpp->parse( $source ); is( scalar( @{$tree->{root}->{one}} ), 1, "B: one force_array node" ); is( scalar( @{$tree->{root}->{two}} ), 2, "B: two child nodes" ); is( scalar( @{$tree->{root}->{three}} ), 3, "B: three empty nodes" ); is( scalar( grep {ref $_} @{$tree->{root}->{one}} ), 1, "B: one force_array node" ); is( scalar( grep {ref $_} @{$tree->{root}->{two}} ), 2, "B: two child nodes" ); is( scalar( grep {ref $_} @{$tree->{root}->{three}} ), 3, "B: three empty nodes" ); } # ---------------------------------------------------------------- { my $tpp = XML::TreePP->new( force_array => '*' ); my $source = <<"EOT"; 1 3 EOT my $tree = $tpp->parse( $source ); is( ref $tree->{root}, 'ARRAY', 'C: root ARRAY' ); is( ref $tree->{root}->[0], 'HASH', 'C: root HASH' ); is( ref $tree->{root}->[0]->{one}, 'ARRAY', 'C: one ARRAY' ); is( $tree->{root}->[0]->{one}->[0], '1', 'C: one text' ); is( ref $tree->{root}->[0]->{two}, 'ARRAY', 'C: two ARRAY' ); is( ref $tree->{root}->[0]->{two}->[0], 'HASH', 'C: two HASH' ); is( ref $tree->{root}->[0]->{two}->[0]->{three}, 'ARRAY', 'C: three ARRAY' ); is( $tree->{root}->[0]->{two}->[0]->{three}->[0], '3', 'C: three text' ); } # ---------------------------------------------------------------- ;1; # ----------------------------------------------------------------