zeroclickinfo-goodies/t/HTMLEntitiesEncode.t

66 lines
2.5 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'html_entity';
ddg_goodie_test(
[qw(DDG::Goodie::HTMLEntitiesEncode)],
# A simple test
'html code em dash' => test_zci("Encoded HTML Entity: —", html => qr/mdash/),
# Hyphens in-between don't matter
'html code em-dash' => test_zci("Encoded HTML Entity: —", html => qr/mdash/),
# Quotes don't matter
'html encode "em-dash"' => test_zci("Encoded HTML Entity: —", html => qr/mdash/),
# Variety in querying accented chars #1
'html entity A-acute' => test_zci("Encoded HTML Entity: Á",html => qr/Aacute/),
# Variety in querying accented chars #2
'html entity for E grave' => test_zci("Encoded HTML Entity: È", html => qr/Egrave/),
# Query is a single typed-in character to encode
'html escape &' => test_zci("Encoded HTML Entity: &", html => qr/amp/),
# Single typed-in character query with (ignored) 'sign'
'$ sign htmlentity' => test_zci("Encoded HTML Entity: $", html => qr/#36/),
# Return two matching entities for ambiguous query
'pound symbol html encode ' => test_zci("Encoded HTML Entity: £\nEncoded HTML Entity: #", html => qr/pound.*#35|#35.*pound/),
# Ignore both 'of' and 'sign'
'html code of pilcrow sign' => test_zci("Encoded HTML Entity: ¶", html => qr/#182/),
# Ignore 'symbol'
'html escape greater than symbol' => test_zci("Encoded HTML Entity: >", html => qr/gt/),
# Handle extra space
'space html character code' => test_zci("Encoded HTML Entity:  ", html => qr/nbsp/),
# Mixed cases in query
'ApoSTrophe escapehtml' => test_zci("Encoded HTML Entity: '", html => qr/#39/),
# 'right angle brackets' should work even though the defined key contains the singular 'bracket'
'right angle brackets htmlencode' => test_zci("Encoded HTML Entity: ›\nEncoded HTML Entity: »", html => qr/rsaquo.*raquo|raquo.*rsaquo/),
# 'double quotes' should work even though the defined key contains the singular 'quote'
'double quotes htmlescape' => test_zci("Encoded HTML Entity: "", html => qr/quot/),
# Should not work (would make sense to decode the query though!)
'html encode +' => undef,
# Should not work (would make sense to decode the query though!)
'html entity &' => undef,
# Should not work
'html encode is it magic' => undef,
);
done_testing;