From: Grant M. <gr...@us...> - 2004-11-17 08:36:59
|
Update of /cvsroot/perl-xml/xml-simple/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14674/t Modified Files: 2_XMLout.t Log Message: - fix inconsistencies in SuppressEmpty with XMLout Index: 2_XMLout.t =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/t/2_XMLout.t,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- 2_XMLout.t 17 Nov 2004 08:35:12 -0000 1.13 +++ 2_XMLout.t 17 Nov 2004 08:36:49 -0000 1.14 @@ -7,7 +7,7 @@ $^W = 1; -plan tests => 193; +plan tests => 196; ############################################################################## @@ -654,21 +654,20 @@ local($^W) = 1; my $warn = ''; local $SIG{__WARN__} = sub { $warn = $_[0] }; - $_ = eval { - $ref = { 'tag' => undef }; - XMLout($ref); - }; + $ref = { 'one' => 1, 'two' => undef }; + my $expect = qr/^<\w+(\s+one="1"|\s+two=""){2}/; + + $_ = XMLout($ref); like($warn, qr/Use of uninitialized value/, 'caught warning re uninitialised value'); + like($_, $expect, 'undef maps to any empty attribute by default'); # unless warnings are disabled $^W = 0; $warn = ''; - $_ = eval { - $ref = { 'tag' => undef }; - XMLout($ref); - }; + $_ = XMLout($ref); is($warn, '', 'no warning re uninitialised value if warnings off'); + like($_, $expect, 'undef still maps to any empty attribute'); } @@ -680,6 +679,14 @@ 'uninitialiased values successfully mapped to empty elements'); +# Set suppressempty to 1 to not output anything for undef + +$ref = { 'one' => 1, 'two' => undef }; +$_ = XMLout($ref, suppressempty => 1, noattr => 1); +like($_, qr{^\s*<(\w*)\s*>\s*<one\s*>1</one\s*>\s*</\1\s*>\s*$}s, + 'uninitialiased values successfully skipped'); + + # Test the keeproot option $ref = { |