/XML-TreePP/t/05_empty.t

http://xml-treepp.googlecode.com/ · Raku · 29 lines · 21 code · 4 blank · 4 comment · 2 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. ok( exists $tree->{root}->{e1}, "empty element" );
  10. ok( ref $tree->{root}->{e2}, "empty element with attribute" );
  11. ok( exists $tree->{root}->{e3}, "no child nodes" );
  12. ok( ref $tree->{root}->{e4}, "attribute" );
  13. ok( exists $tree->{root}->{e5}, "white space" );
  14. my $xml = $tpp->write( $tree );
  15. my $round = $tpp->parse( $xml );
  16. ok( exists $round->{root}->{e1}, "round trip: empty element" );
  17. ok( ref $round->{root}->{e2}, "round trip: empty element with attribute" );
  18. ok( exists $round->{root}->{e3}, "round trip: no child nodes" );
  19. ok( ref $round->{root}->{e4}, "round trip: attribute" );
  20. ok( exists $round->{root}->{e5}, "round trip: white space" );
  21. is( $tree->{root}->{e2}->{"-foo"}, $round->{root}->{e2}->{"-foo"}, "round trip: attribute 1" );
  22. is( $tree->{root}->{e4}->{"-foo"}, $round->{root}->{e4}->{"-foo"}, "round trip: attribute 2" );
  23. # ----------------------------------------------------------------
  24. ;1;
  25. # ----------------------------------------------------------------