1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#!/usr/bin/perl
use 5.016;
use strict;
use Test::More;
use WWW::Noss::TextToHtml qw(text2html escape_html unescape_html strip_tags);
my $TEST_TEXT = <<'HERE';
> This is a paragraph.
>< This is another paragraph.
>& This is an additional paragraph.
HERE
my $TEST_ENTITY = '<>< && << >> &&';
my $text2html = text2html($TEST_TEXT);
like(
$text2html,
qr/\Q> This is a paragraph.\E/,
'text2html retained paragraphs'
);
like(
$text2html,
qr/\Q>< This is another paragraph.\E/,
'text2html retained paragraphs'
);
like(
$text2html,
qr/\Q>& This is an additional paragraph.\E/,
'text2html retained paragraphs'
);
like(
$text2html,
qr/(<p>.+?<\/p>.*?){3}/s,
'text2html added paragraph tags'
);
is(
escape_html($TEST_ENTITY),
'<>< && << >> &&',
'escape_html performed entity conversions correctly'
);
subtest 'unescape_html ok' => sub {
is(
unescape_html('HELLO'),
'HELLO',
'numerical entities ok'
);
is(
unescape_html('HELLO'),
'HELLO',
'hexadecimal entities ok'
);
is(
unescape_html('ΑΒΓΔΕ'),
join('', map { chr } 913 .. 917),
'named entities ok'
);
is(
unescape_html('&amp;'),
'&',
'expanding into entities ok'
);
};
subtest 'strip_tags ok' => sub {
is(
strip_tags('<p>Some</p><h1>Test</h1><div class="test">Text</div>'),
'SomeTestText',
'strip_tags ok'
);
is(
strip_tags('<p <!-- yadda yadda -->>Test</p><h1 <!-- -->>Text</h1>'),
'TestText',
'nested tags ok'
);
is(
strip_tags('<p>Test<![CDATA[ < > & >:-) ]]>Text</p>'),
'TestText',
'CDATA ok'
);
};
done_testing;
# vim: expandtab shiftwidth=4
|