summaryrefslogtreecommitdiff
path: root/ext/HTML/Parser/t/uentities.t
blob: b9decc54a03b59ce621b18d7b44e36119da97a98 (plain)
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
# Test Unicode entities

use HTML::Entities;

use Test::More tests => 27;

SKIP: {
skip "This perl does not support Unicode or Unicode entities not selected",
  27 if $] < 5.008 || !&HTML::Entities::UNICODE_SUPPORT;

is(decode_entities("&euro"), "&euro");
is(decode_entities("&euro;"), "\x{20AC}");

is(decode_entities("&aring"), "å");
is(decode_entities("&aring;"), "å");

is(decode_entities("&#500000"), chr(500000));

is(decode_entities("&#x10FFFD"), "\x{10FFFD}");

is(decode_entities("&#xFFFC"), "\x{FFFC}");


is(decode_entities("&#xFDD0"), "\x{FFFD}");
is(decode_entities("&#xFDD1"), "\x{FFFD}");
is(decode_entities("&#xFDE0"), "\x{FFFD}");
is(decode_entities("&#xFDEF"), "\x{FFFD}");
is(decode_entities("&#xFFFF"), "\x{FFFD}");
is(decode_entities("&#x10FFFF"), "\x{FFFD}");
is(decode_entities("&#x110000"), chr(0xFFFD));
is(decode_entities("&#XFFFFFFFF"), chr(0xFFFD));

is(decode_entities("&#0"), "\0");
is(decode_entities("&#0;"), "\0");
is(decode_entities("&#x0"), "\0");
is(decode_entities("&#X0;"), "\0");

is(decode_entities("&#&aring&#229&#229;&#xFFF"), "&#ååå\x{FFF}");

# This might fail when we get more than 64 bit UVs
is(decode_entities("&#0009999999999999999999999999999;"), "&#0009999999999999999999999999999;");
is(decode_entities("&#xFFFF0000FFFF0000FFFF1"), "&#xFFFF0000FFFF0000FFFF1");

my $err;
for ([32, 48], [120, 169], [240, 250], [250, 260], [965, 975], [3000, 3005]) {
    my $a = join("", map chr, $_->[0] .. $_->[1]);

    my $e = encode_entities($a);
    my $d = decode_entities($e);

    unless ($d eq $a) {
	diag "Wrong decoding in range $_->[0] .. $_->[1]";
	# use Devel::Peek; Dump($a); Dump($d);
	$err++;
    }
}
ok(!$err);


is(decode_entities("&#56256;&#56453;"), chr(0x100085));

is(decode_entities("&#56256;&#56453;"), chr(0x100085));

is(decode_entities("&#56256"), chr(0xFFFD));

is(decode_entities("\260&rsquo;\260"), "\x{b0}\x{2019}\x{b0}");
}