1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
package main;
use strict;
use warnings;
use Test::More tests => 11;
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{<?xml version="1.0" encoding="utf-8"?>};
SKIP: {
use utf8;
my $result = eval { xml2hash('t/test_cp1251.xml') };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
'Привет!',
'test cp1251',
;
}
SKIP: {
my $result = eval { xml2hash('t/test_cp1251.xml', utf8 => 0) };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
'Привет!',
'test cp1251 utf8 off',
;
}
SKIP: {
use utf8;
my $result = eval { xml2hash('t/test_cp1251.xml', encoding => 'cp1251') };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
'Привет!',
'test cp1251 with encoding',
;
}
SKIP: {
my $result = eval { xml2hash('t/test_cp1251.xml', encoding => 'iso-8859-1', utf8 => 0) };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
'Ïðèâåò!',
'test cp1251 without encoding',
;
}
SKIP: {
my $result = eval { xml2hash('t/test_cp1251_wo_decl.xml', utf8 => 0) };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
"\317\360\350\342\345\362!",
'test cp1251 wo decl',
;
}
SKIP: {
use utf8;
my $result = eval { xml2hash('t/test_cp1251_wo_decl.xml', encoding => 'cp1251') };
my $err = $@;
chomp $err;
skip $err, 1 if $err;
is
$result,
"Привет!",
'test cp1251 wo decl with encoding',
;
}
{
use utf8;
is
xml2hash('t/test_utf8.xml'),
"Привет!",
'test utf8',
;
}
{
use utf8;
is
xml2hash('t/test_utf8.xml', encoding => 'utf-8'),
"Привет!",
'test utf8 with encoding',
;
}
{
is
xml2hash('t/test_utf8.xml', utf8 => 0),
"Привет!",
'test utf8 with utf8 off',
;
}
{
is
xml2hash('<root>Привет!</root>', utf8 => 0),
"Привет!",
'test utf8 string with utf8 off',
;
}
{
use utf8;
is
xml2hash('<root>Привет!</root>'),
"Привет!",
'test utf8 string with utf8 on',
;
}
|