Commit | Line | Data |
d6512b50 |
1 | use strict; |
2 | use warnings; |
3 | use utf8; |
4 | use Test::More; |
e085469f |
5 | use DOM::Tiny::Entities qw(html_escape html_unescape); |
d6512b50 |
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 ☃ ∳ bar ¹baz'), |
14 | "foo ☃ \x{2233} bar ¹baz", 'right HTML unescaped result'; |
15 | |
16 | # html_unescape (multi-character entity) |
17 | is html_unescape(decode 'UTF-8', '∾̳'), "\x{223e}\x{0333}", |
18 | 'right HTML unescaped result'; |
19 | |
20 | # html_unescape (apos) |
21 | is html_unescape('foobar'<baz>&"'), "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 (UTF-8) |
28 | is html_unescape(decode 'UTF-8', 'foo<baz>&"Œ&Foo;'), |
29 | "foo<baz>&\"\x{152}&Foo;", 'right HTML unescaped result'; |
30 | |
e085469f |
31 | # html_escape |
32 | is html_escape(qq{la<f>\nbar"baz"'yada\n'<la}), |
d6512b50 |
33 | "la<f>\nbar"baz"'yada\n'&lt;la", |
e085469f |
34 | 'right HTML escaped result'; |
d6512b50 |
35 | |
e085469f |
36 | # html_escape (UTF-8 with nothing to escape) |
37 | is html_escape('привет'), 'привет', 'right HTML escaped result'; |
d6512b50 |
38 | |
e085469f |
39 | # html_escape (UTF-8) |
40 | is html_escape('привет<foo>'), 'привет<foo>', |
41 | 'right HTML escaped result'; |
d6512b50 |
42 | |
43 | done_testing; |