package main; use strict; use warnings; use Test::More tests => 10; use Data::Dumper; $Data::Dumper::Indent = 0; $Data::Dumper::Sortkeys = 1; use XML::Hash::XS 'xml2hash'; $XML::Hash::XS::keep_root = 0; our $xml_decl_utf8 = qq{}; { is Dumper(xml2hash(<<"XML", keep_root => 1, content => 'text', trim => 1)), value1 value2 content1 content2 content1 content2 1 2 3 ]]> ]]]]]]> XML Dumper({ root => { attr1 => '1', attr2 => '2', cdata => 'abcde!@#0^&*<>', cdata2 => 'abc ]', cdata3 => '[ abc ] ]> ]]]]', item => ['1', '2', '3'], node1 => 'value1', node2 => { attr1 => '1', text => 'value2', }, node3 => ['content1', 'content2'], node4 => { text => ['content1', 'content2'], empty_node4 => '', }, } }), 'complex', ; } { use utf8; my $xml = <<'XML'; Test XML no warnings qw(void); substr $xml, 0, 0; # this will cause error in XS param type definition is xml2hash(\$xml, trim => 1), 'Test', 'check validation parameters', ; } { my $xml=qq[\x0D\x0A\x0D\x0Aasdasdsa\x0D\x0A]; is xml2hash(\$xml, trim => 1), 'asdasdsa', 'bug RT#103002', ; } { my $xml=qq[\x0D\x0Aasd\x0D\x0Aasd\x0D\x0D\x0Aasd\x0D\x0A]; is xml2hash(\$xml, trim => 1), "asd\x0Aasd\x0A\x0Aasd", 'normalize line feeds', ; } { is Dumper(xml2hash(<<"XML")), bbbdddfffggg XML Dumper({aaa => { content => ['bbb', 'ddd', 'ggg'], eee => 'fff' }}), 'bug with many contents in the one node', ; } { eval { xml2hash("") }; ok($@, 'invalid xml'); } { eval { xml2hash("") }; ok($@, 'invalid xml2'); } { eval { xml2hash("") }; ok($@, 'invalid xml3'); } { eval { xml2hash("text") }; ok($@, 'invalid xml4'); } { is Dumper(xml2hash(<<"XML")), XML Dumper({ row => [ {cell => {'text' => "test's"}}, {cell => {'text' => " test's"}}, ], }), 'memory allocation bug', ; }