PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/XML-TreePP/t/05_empty.t

http://xml-treepp.googlecode.com/
Unknown | 29 lines | 25 code | 4 blank | 0 comment | 0 complexity | f182326257354d1541ec7bd8ba42b11c MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 13;
 4    BEGIN { use_ok('XML::TreePP') };
 5# ----------------------------------------------------------------
 6    my $tpp = XML::TreePP->new( force_array => [qw( one two three )] );
 7    my $source = '<root> <e1/> <e2 foo="bar"/> <e3></e3> <e4 foo="bar"></e4> <e5> </e5> </root>';
 8    my $tree = $tpp->parse( $source );
 9
10    ok( exists $tree->{root}->{e1}, "empty element" );
11    ok( ref $tree->{root}->{e2},    "empty element with attribute" );
12    ok( exists $tree->{root}->{e3}, "no child nodes" );
13    ok( ref $tree->{root}->{e4},    "attribute" );
14    ok( exists $tree->{root}->{e5}, "white space" );
15
16    my $xml = $tpp->write( $tree );
17    my $round = $tpp->parse( $xml );
18
19    ok( exists $round->{root}->{e1}, "round trip: empty element" );
20    ok( ref $round->{root}->{e2},    "round trip: empty element with attribute" );
21    ok( exists $round->{root}->{e3}, "round trip: no child nodes" );
22    ok( ref $round->{root}->{e4},    "round trip: attribute" );
23    ok( exists $round->{root}->{e5}, "round trip: white space" );
24
25    is( $tree->{root}->{e2}->{"-foo"}, $round->{root}->{e2}->{"-foo"}, "round trip: attribute 1" );
26    is( $tree->{root}->{e4}->{"-foo"}, $round->{root}->{e4}->{"-foo"}, "round trip: attribute 2" );
27# ----------------------------------------------------------------
28;1;
29# ----------------------------------------------------------------