7d8f879c6a8b16a74e1108e182f57e76c8abad46
[catagits/DOM-Tiny.git] / t / entities.t
1 use strict;
2 use warnings;
3 use utf8;
4 use Test::More;
5 use DOM::Tiny::Entities qw(html_escape html_unescape);
6 use Encode 'decode';
7
8 # html_unescape
9 is html_unescape('<foo>bar<baz>&"'),
10   "<foo>bar<baz>&\"", 'right HTML unescaped result';
11
12 # html_unescape (special entities)
13 is html_unescape('foo &#x2603; &CounterClockwiseContourIntegral; bar &sup1baz'),
14   "foo ☃ \x{2233} bar &sup1baz", 'right HTML unescaped result';
15
16 # html_unescape (multi-character entity)
17 is html_unescape(decode 'UTF-8', '&acE;'), "\x{223e}\x{0333}",
18   'right HTML unescaped result';
19
20 # html_unescape (apos)
21 is html_unescape('foobar&apos;&lt;baz&gt;&#x26;&#34;'), "foobar'<baz>&\"",
22   'right HTML unescaped result';
23
24 # html_unescape (nothing to unescape)
25 is html_unescape('foobar'), 'foobar', 'right HTML unescaped result';
26
27 # html_unescape (bengal numbers with nothing to unescape)
28 is html_unescape('&#০৩৯;&#x০৩৯;'), '&#০৩৯;&#x০৩৯;', 'no changes';
29
30 # html_unescape (UTF-8)
31 is html_unescape(decode 'UTF-8', 'foo&lt;baz&gt;&#x26;&#34;&OElig;&Foo;'),
32   "foo<baz>&\"\x{152}&Foo;", 'right HTML unescaped result';
33
34 # html_escape
35 is html_escape(qq{la<f>\nbar"baz"'yada\n'&lt;la}),
36   "la&lt;f&gt;\nbar&quot;baz&quot;&#39;yada\n&#39;&amp;lt;la",
37   'right HTML escaped result';
38
39 # html_escape (UTF-8 with nothing to escape)
40 is html_escape('привет'), 'привет', 'right HTML escaped result';
41
42 # html_escape (UTF-8)
43 is html_escape('привет<foo>'), 'привет&lt;foo&gt;',
44   'right HTML escaped result';
45
46 done_testing;