Bump version
[catagits/DOM-Tiny.git] / t / entities.t
CommitLineData
d6512b50 1use strict;
2use warnings;
3use utf8;
4use Test::More;
e085469f 5use DOM::Tiny::Entities qw(html_escape html_unescape);
d6512b50 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
4d7ffd97 27# html_unescape (bengal numbers with nothing to unescape)
28is html_unescape('&#০৩৯;&#x০৩৯;'), '&#০৩৯;&#x০৩৯;', 'no changes';
29
d6512b50 30# html_unescape (UTF-8)
31is html_unescape(decode 'UTF-8', 'foo&lt;baz&gt;&#x26;&#34;&OElig;&Foo;'),
32 "foo<baz>&\"\x{152}&Foo;", 'right HTML unescaped result';
33
e085469f 34# html_escape
35is html_escape(qq{la<f>\nbar"baz"'yada\n'&lt;la}),
d6512b50 36 "la&lt;f&gt;\nbar&quot;baz&quot;&#39;yada\n&#39;&amp;lt;la",
e085469f 37 'right HTML escaped result';
d6512b50 38
e085469f 39# html_escape (UTF-8 with nothing to escape)
40is html_escape('привет'), 'привет', 'right HTML escaped result';
d6512b50 41
e085469f 42# html_escape (UTF-8)
43is html_escape('привет<foo>'), 'привет&lt;foo&gt;',
44 'right HTML escaped result';
d6512b50 45
46done_testing;