reference collection methods section
[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
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
e085469f 31# html_escape
32is html_escape(qq{la<f>\nbar"baz"'yada\n'&lt;la}),
d6512b50 33 "la&lt;f&gt;\nbar&quot;baz&quot;&#39;yada\n&#39;&amp;lt;la",
e085469f 34 'right HTML escaped result';
d6512b50 35
e085469f 36# html_escape (UTF-8 with nothing to escape)
37is html_escape('привет'), 'привет', 'right HTML escaped result';
d6512b50 38
e085469f 39# html_escape (UTF-8)
40is html_escape('привет<foo>'), 'привет&lt;foo&gt;',
41 'right HTML escaped result';
d6512b50 42
43done_testing;