From: Grant M. <gr...@us...> - 2003-04-16 10:17:44
|
Update of /cvsroot/perl-xml/xml-simple/t In directory sc8-pr-cvs1:/tmp/cvs-serv12018/t Modified Files: 1_XMLin.t Log Message: - added tests for regexes in ForceArray Index: 1_XMLin.t =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/t/1_XMLin.t,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- 1_XMLin.t 10 Apr 2003 10:20:06 -0000 1.11 +++ 1_XMLin.t 16 Apr 2003 10:17:29 -0000 1.12 @@ -15,14 +15,14 @@ plan skip_all => 'Test data missing'; } -plan tests => 93; +plan tests => 95; $@ = ''; eval "use XML::Simple;"; is($@, '', 'Module compiled OK'); -unless($XML::Simple::VERSION eq '2.04') { - diag("Warning: XML::Simple::VERSION = $XML::Simple::VERSION (expected 2.04)"); +unless($XML::Simple::VERSION eq '2.05') { + diag("Warning: XML::Simple::VERSION = $XML::Simple::VERSION (expected 2.05)"); } @@ -670,6 +670,41 @@ 'two' => [ 'ii' ], 'three' => [ 'iii', 3, 'c' ] }, 'selective application of forcearray successful'); + + +# Test forcearray regexes + +$xml = q(<opt zero="0"> + <one>i</one> + <two>ii</two> + <three>iii</three> + <four>iv</four> + <five>v</five> +</opt> +); + +$opt = XMLin($xml, forcearray => [ qr/^f/, 'two', qr/n/ ], @cont_key); +is_deeply($opt, { + 'zero' => '0', + 'one' => [ 'i' ], + 'two' => [ 'ii' ], + 'three' => 'iii', + 'four' => [ 'iv' ], + 'five' => [ 'v' ], +}, 'forcearray using regex successful'); + + +# Same again but a single regexp rather than in an arrayref + +$opt = XMLin($xml, forcearray => qr/^f|e$/, @cont_key); +is_deeply($opt, { + 'zero' => '0', + 'one' => [ 'i' ], + 'two' => 'ii', + 'three' => [ 'iii'], + 'four' => [ 'iv' ], + 'five' => [ 'v' ], +}, 'forcearray using a single regex successful'); # Test 'noattr' option |