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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#!/usr/bin/perl
# $Version: release/perl/base/XML-Quote/t/quote.t,v 1.6 2003/01/31 09:13:12 godegisel Exp $
package TEST_OVERLOAD;
use overload '""' => sub {${$_[0]} ? 'true' : 'false'};
sub new {
my $v=$_[1];
bless \$v, $_[0];
}
package TEST_TIED;
sub TIESCALAR {
my $val=$_[1];
bless \$val, $_[0];
}
sub FETCH {
uc(${$_[0]});
}
sub STORE {
${$_[0]}=$_[1];
}
package main;
use strict;
use utf8;
use Test::More tests => 48;
BEGIN {use_ok('XML::Quote')};
my @tests=(
[
"amp",
"amp",
],
[
"&",
"&",
],
[
qq{&"'><},
"&"'><",
],
[
"&",
"&amp;",
],
[
"\0",
"\0",
],
[
'plain text without any special symbols',
'plain text without any special symbols',
],
[
44,
44,
],
[
123.11,
123.11,
],
[
'некий "тест >в <\'ютф8 &',
q{некий "тест >в <'ютф8 &},
],
);
my ($to_quote, $expected, $quoted, $dequoted);
for my $arr (@tests) {
my ($to_quote, $expected)=@$arr;
my $quoted=XML::Quote::xml_quote($to_quote);
is($quoted, $expected, 'xml_quote:'.$to_quote);
my $dequoted=XML::Quote::xml_dequote($quoted);
is($dequoted, $to_quote, 'xml_dequote:'.$expected);
}#for
my @tests_min=(
[
"amp",
"amp",
],
[
"&",
"&",
],
[
qq{&"'><},
"&"'><",
],
[
"\0",
"\0",
],
[
'plain text without any special symbols',
'plain text without any special symbols',
],
[
44,
44,
],
[
123.11,
123.11,
],
[
'некий "тест >в <\'ютф8 &',
q{некий "тест >в <'ютф8 &},
],
);
for my $arr (@tests_min) {
my ($to_quote, $expected)=@$arr;
my $quoted=XML::Quote::xml_quote_min($to_quote);
is($quoted, $expected, 'xml_quote_min:'.$to_quote);
my $dequoted=XML::Quote::xml_dequote($quoted);
is($dequoted, $to_quote, 'xml_dequote:'.$expected);
}#for
my @tests_overload=(
[
TEST_OVERLOAD->new(1),
'true',
],
[
TEST_OVERLOAD->new(0),
'false',
],
);
for my $arr (@tests_overload) {
my ($to_quote, $expected)=@$arr;
my $quoted=XML::Quote::xml_quote($to_quote);
is($quoted, $expected, 'over xml_quote:'.$to_quote);
my $dequoted=XML::Quote::xml_dequote($quoted);
is($dequoted, "$to_quote", 'over xml_dequote:'.$expected);
}#for
tie(my $tied_scalar,'TEST_TIED');
$tied_scalar='test&rest';
my @tests_tied=(
[
$tied_scalar,
'TEST&REST',
],
);
use Devel::Peek;
for my $arr (@tests_tied) {
my ($to_quote, $expected)=@$arr;
my $quoted=XML::Quote::xml_quote($to_quote);
is($quoted, $expected, 'tied xml_quote:'.$to_quote);
my $dequoted=XML::Quote::xml_dequote($quoted);
is($dequoted, "$to_quote", 'tied xml_dequote:'.$expected);
}#for
my @tests2=(
['&','&'],
['"','"'],
[''','\''],
['><','><'],
['&160','&160'],
['&;','&;'],
['&','&'],
);
#use Devel::Peek;
for my $arr (@tests2) {
my ($bef,$aft)=@$arr;
# Dump($bef);
my $cvt=XML::Quote::xml_dequote($bef);
# Dump($aft);
# Dump($cvt);
is($cvt, $aft, 'xml_dequote:'.$bef);
}#for
|