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