HTMLEntitiesDecode: Converting to Text Template
parent
3b32b27bc8
commit
4d46a1e103
|
@ -44,12 +44,18 @@ handle remainder => sub {
|
|||
$decoded = "Special character (no visual representation)";
|
||||
}
|
||||
|
||||
# Make answer
|
||||
return "Decoded HTML Entity: $decoded",
|
||||
structured_answer => {
|
||||
input => [$_],
|
||||
result => $decoded,
|
||||
operation => "HTML Entity Decode"
|
||||
data => {
|
||||
title => html_enc($decoded),
|
||||
subtitle => 'HTML Entity Decode: '.html_enc($_)
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
options => {
|
||||
content => 'DDH.html_entity.content'
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -9,11 +9,19 @@ use DDG::Test::Goodie;
|
|||
zci answer_type => 'html_entity';
|
||||
zci is_cached => 1;
|
||||
|
||||
sub any_structured_answer {
|
||||
sub build_structured_answer {
|
||||
my ($title, $subtitle) = @_;
|
||||
return {
|
||||
input => ignore(),
|
||||
result => ignore(),
|
||||
operation => "HTML Entity Decode"
|
||||
data => {
|
||||
title => $title,
|
||||
subtitle => $subtitle,
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
options => {
|
||||
content => 'DDH.html_entity.content'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,32 +29,32 @@ ddg_goodie_test(
|
|||
[qw(DDG::Goodie::HTMLEntitiesDecode)],
|
||||
|
||||
# Simple decimal test
|
||||
'html decode !' => test_zci("Decoded HTML Entity: !", structured_answer => any_structured_answer()),
|
||||
'html decode !' => test_zci("Decoded HTML Entity: !", structured_answer => build_structured_answer("!", "HTML Entity Decode: !")),
|
||||
# Simple text test
|
||||
'html entity &' => test_zci("Decoded HTML Entity: &", structured_answer => any_structured_answer()),
|
||||
'html entity &' => test_zci("Decoded HTML Entity: &", structured_answer => build_structured_answer("&","HTML Entity Decode: &")),
|
||||
# Another simple text test
|
||||
'decode html for >' => test_zci("Decoded HTML Entity: >", structured_answer => any_structured_answer()),
|
||||
'decode html for >' => test_zci("Decoded HTML Entity: >", structured_answer => build_structured_answer(">","HTML Entity Decode: >")),
|
||||
# Simple hex test
|
||||
'! htmlentity' => test_zci("Decoded HTML Entity: !", structured_answer => any_structured_answer()),
|
||||
'! htmlentity' => test_zci("Decoded HTML Entity: !", structured_answer => build_structured_answer("!","HTML Entity Decode: &#x21")),
|
||||
|
||||
# No "&" and ";" in decimal input
|
||||
'#36 html decode' => test_zci("Decoded HTML Entity: \$", structured_answer => any_structured_answer()),
|
||||
'#36 html decode' => test_zci('Decoded HTML Entity: $', structured_answer => build_structured_answer('$',"HTML Entity Decode: #36")),
|
||||
# Variety in hex queries
|
||||
'" decodehtml' => test_zci("Decoded HTML Entity: \"", structured_answer => any_structured_answer()),
|
||||
'" decodehtml' => test_zci('Decoded HTML Entity: "', structured_answer => build_structured_answer('"',"HTML Entity Decode: &#X22")),
|
||||
# More variety in hex queries
|
||||
'htmlentity for #x3c' => test_zci("Decoded HTML Entity: <", structured_answer => any_structured_answer()),
|
||||
'htmlentity for #x3c' => test_zci("Decoded HTML Entity: <", structured_answer => build_structured_answer("<","HTML Entity Decode: #x3c")),
|
||||
|
||||
# "¢" succeeds
|
||||
'html decode ¢' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()),
|
||||
'html decode ¢' => test_zci(qr/.*/, structured_answer => build_structured_answer("¢","HTML Entity Decode: &cent;")),
|
||||
# "¢" also succeeds (missing back ";" is OK)
|
||||
'html decode ¢' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()),
|
||||
'html decode ¢' => test_zci(qr/.*/, structured_answer => build_structured_answer("¢","HTML Entity Decode: &cent")),
|
||||
# "cent" fails during the regex match because of the missing front "&" (stricter for text to eliminate false positive encoding hits)
|
||||
'html decode cent' => undef,
|
||||
# "cent;" fails during the regex match for the same reasons as above
|
||||
'html decode cent;' => undef,
|
||||
|
||||
# "" has no visual representation
|
||||
'html entity of ' => test_zci("Decoded HTML Entity: Unicode control character (no visual representation)", structured_answer => any_structured_answer()),
|
||||
'html entity of ' => test_zci("Decoded HTML Entity: Unicode control character (no visual representation)", structured_answer => build_structured_answer("Unicode control character (no visual representation)","HTML Entity Decode: &#20;")),
|
||||
|
||||
# Querying for "&bunnyrabbit;" should fail
|
||||
'html decode &bunnyrabbit;' => undef,
|
||||
|
@ -56,11 +64,12 @@ ddg_goodie_test(
|
|||
'html decode apostrophe' => undef,
|
||||
|
||||
# natural querying
|
||||
'What is the decoded html entity for π?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()),
|
||||
'What is the decoded html entity for π?' => test_zci(qr/.*/, structured_answer => build_structured_answer("π","HTML Entity Decode: &#960;")),
|
||||
|
||||
# natural querying
|
||||
'what is decoded html entity for #960 ?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()),
|
||||
'what is decoded html entity for #960 ?' => test_zci(qr/.*/, structured_answer => build_structured_answer("π","HTML Entity Decode: #960")),
|
||||
# no "html" in query
|
||||
'the decoded entity for ō is?' => test_zci(re(qr/.*/), structured_answer => any_structured_answer()),
|
||||
'the decoded entity for ō is?' => test_zci(qr/.*/, structured_answer => build_structured_answer("ō","HTML Entity Decode: &#333;")),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue