use strict;
use warnings;
use Test::More tests => 15;
use XML::Hash::XS 'hash2xml';
$XML::Hash::XS::method = 'LX';
$XML::Hash::XS::trim = 1;
our $xml_decl = qq{\n};
{
is
hash2xml( { root => { '#text' => ' zzzz ' } } ),
qq{$xml_declzzzz},
'text',
;
}
{
is
hash2xml( { root => { sub => 'test' } } ),
qq{$xml_decltest},
'node',
;
}
{
is
hash2xml( { root => { -attr => "test < > & \" \t \n \r end" } } ),
qq{$xml_decl},
'attr',
;
}
{
is
hash2xml( { root => { _attr => "test" } }, attr => '_' ),
qq{$xml_decl},
'attr _',
;
}
{
is
hash2xml( { root => { '~' => "zzzz < > & \r end" } }, text => '~' ),
qq{$xml_declzzzz < > &
end},
'text ~',
;
}
{
is
hash2xml( { root => " \t\ntest" }, trim => 1 ),
qq{$xml_decltest},
'trim 1',
;
is
hash2xml( { root => " \t\ntest" }, trim => 0 ),
qq{$xml_decl \t\ntest},
'trim 0',
;
}
{
is
hash2xml( { root => { sub => { '@' => "cdata < > & \" \t \n \r end" } } }, cdata => '@' ),
qq{$xml_decl & \" \t \n \r end]]>},
'cdata @',
;
}
{
is
hash2xml( { root => { sub => { '/' => "comment < > & \" \t \n \r end" } } },comm => '/' ),
qq{$xml_decl},
'comm /',
;
}
{
is
hash2xml( { root => { -attr => undef } } ),
qq{$xml_decl},
'empty attr',
;
}
{
is
hash2xml( { root => { '#cdata' => undef } }, cdata => '#cdata' ),
qq{$xml_decl},
'empty cdata',
;
}
{
is
hash2xml( { root => { '/' => undef } }, comm => '/' ),
qq{$xml_decl},
'empty comment',
;
}
{
is
hash2xml( { root => { x=>undef } } ),
qq{$xml_decl},
'empty tag',
;
}
{
is
hash2xml( { root => { item => [1, 2, 3, { -attr => 4, node => 5 }, [6, 7] ] } } ),
qq{$xml_decl- 1
- 2
- 3
- 5
- 6
- 7
},
'array',
;
}
SKIP: {
my $data;
eval { $data = hash2xml( { root => { test => "Тест" } }, encoding => 'cp1251' ) };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$data,
qq{\n\322\345\361\362},
'encoding support',
;
}