/XML-TreePP/t/37_undef.t

http://xml-treepp.googlecode.com/ · Raku · 35 lines · 28 code · 2 blank · 5 comment · 0 complexity · 14928ecc803e76b000c0575ba2d8ff8f MD5 · raw file

  1. # ----------------------------------------------------------------
  2. use strict;
  3. use Test::More;
  4. # ----------------------------------------------------------------
  5. {
  6. plan tests => 6;
  7. use_ok('XML::TreePP');
  8. &test_undef( first_out => [qw( attr hash list empty undef -one -two three four )] );
  9. }
  10. # ----------------------------------------------------------------
  11. sub test_undef {
  12. my $tpp = XML::TreePP->new(@_);
  13. my $empty = '';
  14. my $undef = undef;
  15. my $tree = {
  16. root => {
  17. attr => { -one=>'', -two=>undef },
  18. hash => { three => '', four => undef },
  19. list => [ '', undef ],
  20. empty => \$empty,
  21. undef => \$undef,
  22. }
  23. };
  24. my $xml = $tpp->write( $tree );
  25. like( $xml, qr{<attr one="" two=""}, 'attr one two' );
  26. like( $xml, qr{ <hash>\s*<three }xs, 'hash three' );
  27. like( $xml, qr{ </three>\s*<four }xs, 'hash four' );
  28. like( $xml, qr{ <empty><!\[CDATA\[ }xs, 'empty cdata' );
  29. like( $xml, qr{ <undef><!\[CDATA\[ }xs, 'undef cdata' );
  30. }
  31. # ----------------------------------------------------------------
  32. ;1;
  33. # ----------------------------------------------------------------