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