From: Grant M. <gr...@us...> - 2004-04-05 09:25:29
|
Update of /cvsroot/perl-xml/xml-simple/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6360/t Modified Files: 1_XMLin.t 2_XMLout.t 8_Namespaces.t Log Message: - added NumericEscape option - added ValueAttr option (patch from Anton Berezin) - suppress 'wide character in print' warning (reported by Dawei Lin) Index: 2_XMLout.t =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/t/2_XMLout.t,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- 2_XMLout.t 2 Mar 2004 08:17:45 -0000 1.11 +++ 2_XMLout.t 5 Apr 2004 09:12:51 -0000 1.12 @@ -7,7 +7,7 @@ $^W = 1; -plan tests => 185; +plan tests => 190; ############################################################################## @@ -1076,6 +1076,46 @@ } +# Check ValueAttr => {} can expand the relevant records + +$ref = { one => 1, two => 2, six => 6 }; + +$xml = XMLout($ref, ValueAttr => { one => 'value', six => 'num' }); + +like($xml, qr{ + ^<opt\s+two="2"\s*> + ( + \s*<one\s+value="1"\s*/> + | \s*<six\s+num="6"\s*/> + ){2} + \s*</opt>$ + }sx, 'Correct attributes inserted when ValueAttr specified' +); + +# Try out the NumericEscape option + +SKIP: { + skip "Perl 5.6 or better required", 4 unless($] >= 5.006); + + $ref = { euro => "\x{20AC}", nbsp => "\x{A0}" }; + + $xml = XMLout($ref); # Default: no numeric escaping + my $ents = join ',', sort ($xml =~ m{&#(\d+);}g); + is($ents, '', "No numeric escaping by default"); + + $xml = XMLout($ref, NumericEscape => 0); + $ents = join ',', sort ($xml =~ m{&#(\d+);}g); + is($ents, '', "No numeric escaping: explicit"); + + $xml = XMLout($ref, NumericEscape => 2); + $ents = join ',', sort ($xml =~ m{&#(\d+);}g); + is($ents, '160,8364', "Level 2 numeric escaping looks good"); + + $xml = XMLout($ref, NumericEscape => 1); + $ents = join ',', sort ($xml =~ m{&#(\d+);}g); + is($ents, '8364', "Level 1 numeric escaping looks good"); +} + # 'Stress test' with a data structure that maps to several thousand elements. # Unfold elements with XMLout() and fold them up again with XMLin() Index: 8_Namespaces.t =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/t/8_Namespaces.t,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- 8_Namespaces.t 29 Feb 2004 09:49:18 -0000 1.6 +++ 8_Namespaces.t 5 Apr 2004 09:12:51 -0000 1.7 @@ -22,7 +22,7 @@ plan skip_all => "XML::NamespaceSupport is too old (upgrade to 1.04 or better)"; } -plan tests => 7; +plan tests => 8; ############################################################################## @@ -206,20 +206,24 @@ if($xml =~ m{<list\s+xmlns:(\w+)="http://www.phantom.com/"\s*>}) { $prefix = $1; } + # regex match split in two to workaround 5.8.1/utf8/regex match prob like($xml, qr{ - ^\s*<opt + \s*<opt \s+xmlns="http://www.orgsoc.org/" \s*> - \s*<list\s+xmlns:${prefix}="http://www.phantom.com/"\s*> + .*? + </list> + \s*</opt> +}sx, 'namespace prefixes are generated automatically (part 1)'); + +like($xml, qr{ (\s*<member>Tom</member> \s*<member>Dick</member> \s*<member>Larry</member> |\s*<${prefix}:director>Bill</${prefix}:director> \s*<${prefix}:director>Ben</${prefix}:director>){2} - \s*</list> - \s*</opt> - \s*$ -}sx, 'namespace prefixes are generated automatically'); + #\s*</list> +}sx, 'namespace prefixes are generated automatically (part 2)'); exit(0); |