2016-05-14 12:05:32 -07:00
#!/usr/bin/env perl
2014-06-23 22:12:47 -07:00
use strict ;
use warnings ;
2016-05-12 10:00:09 -07:00
use utf8 ;
2014-06-23 22:12:47 -07:00
use Test::More ;
2016-05-16 06:07:57 -07:00
use Test::Deep ;
2014-06-23 22:12:47 -07:00
use DDG::Test::Goodie ;
zci answer_type = > 'html_entity' ;
2014-09-27 06:42:57 -07:00
zci is_cached = > 1 ;
2014-06-23 22:12:47 -07:00
2016-05-12 05:30:55 -07:00
sub build_structured_answer {
my ( $ title , $ subtitle ) = @ _ ;
2015-08-31 13:48:47 -07:00
return {
2016-05-12 05:30:55 -07:00
data = > {
title = > $ title ,
subtitle = > $ subtitle ,
} ,
templates = > {
2016-05-14 12:05:32 -07:00
group = > 'text'
2016-05-12 05:30:55 -07:00
}
2015-08-31 13:48:47 -07:00
} ;
}
2016-05-12 15:44:50 -07:00
sub build_test {
my ( $ text , $ title , $ subtitle ) = @ _ ;
return test_zci ( $ text , structured_answer = > build_structured_answer ( $ title , $ subtitle ) ) ;
}
2014-06-23 22:12:47 -07:00
ddg_goodie_test (
[ qw( DDG::Goodie::HTMLEntitiesDecode ) ] ,
2014-10-28 11:36:15 -07:00
# Simple decimal test
2016-05-14 12:05:32 -07:00
'html decode !' = > build_test ( "Decoded HTML Entity: !" , "!" , "HTML Entity Decode: !" ) ,
2014-10-28 11:36:15 -07:00
# Simple text test
2016-05-14 12:05:32 -07:00
'html entity &' = > build_test ( "Decoded HTML Entity: &" , "&" , "HTML Entity Decode: &" ) ,
2014-06-23 22:12:47 -07:00
# Another simple text test
2016-05-14 12:05:32 -07:00
'decode html for >' = > build_test ( "Decoded HTML Entity: >" , ">" , "HTML Entity Decode: >" ) ,
2014-10-28 11:36:15 -07:00
# Simple hex test
2016-05-14 12:05:32 -07:00
'! htmlentity' = > build_test ( "Decoded HTML Entity: !" , "!" , "HTML Entity Decode: !" ) ,
2014-06-23 22:12:47 -07:00
# No "&" and ";" in decimal input
2016-05-12 15:44:50 -07:00
'#36 html decode' = > build_test ( 'Decoded HTML Entity: $' , '$' , "HTML Entity Decode: #36" ) ,
2014-06-23 22:12:47 -07:00
# Variety in hex queries
2016-05-14 12:05:32 -07:00
'" decodehtml' = > build_test ( 'Decoded HTML Entity: "' , '"' , "HTML Entity Decode: "" ) ,
2014-06-23 22:12:47 -07:00
# More variety in hex queries
2016-05-14 12:05:32 -07:00
'htmlentity for #x3c' = > build_test ( "Decoded HTML Entity: <" , "<" , "HTML Entity Decode: #x3c" ) ,
2014-06-23 22:12:47 -07:00
# "¢" succeeds
2016-05-14 12:05:32 -07:00
'html decode ¢' = > build_test ( "Decoded HTML Entity: ¢" , '¢' , "HTML Entity Decode: ¢" ) ,
2014-06-23 22:12:47 -07:00
# "¢" also succeeds (missing back ";" is OK)
2016-05-14 12:05:32 -07:00
'html decode ¢' = > build_test ( "Decoded HTML Entity: ¢" , '¢' , "HTML Entity Decode: ¢" ) ,
2014-06-23 22:12:47 -07:00
# "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
2014-10-28 11:36:15 -07:00
'html decode cent;' = > undef ,
2014-06-23 22:12:47 -07:00
# "" has no visual representation
2016-05-14 12:05:32 -07:00
'html entity of ' = > build_test ( "Decoded HTML Entity: Unicode control character (no visual representation)" , "Unicode control character (no visual representation)" , "HTML Entity Decode: " ) ,
2014-10-28 11:36:15 -07:00
2014-06-23 22:12:47 -07:00
# Querying for "&bunnyrabbit;" should fail
'html decode &bunnyrabbit;' = > undef ,
# Trying to decode "&" should fail (this is an encoding job)
'html decode &' = > undef ,
# Trying to decode apostrophe should fail (decode_entities() unsuccessful)
'html decode apostrophe' = > undef ,
2014-06-25 21:28:20 -07:00
# natural querying
2016-05-14 12:05:32 -07:00
'What is the decoded html entity for π?' = > build_test ( "Decoded HTML Entity: π" , "π" , "HTML Entity Decode: π" ) ,
2016-05-12 05:30:55 -07:00
2014-06-25 21:28:20 -07:00
# natural querying
2016-05-14 12:05:32 -07:00
'what is decoded html entity for #960 ?' = > build_test ( "Decoded HTML Entity: π" , "π" , "HTML Entity Decode: #960" ) ,
2014-06-26 15:06:23 -07:00
# no "html" in query
2016-05-14 12:05:32 -07:00
'the decoded entity for ō is?' = > build_test ( "Decoded HTML Entity: ō" , "ō" , "HTML Entity Decode: ō" ) ,
2014-06-23 22:12:47 -07:00
) ;
2016-05-16 06:18:04 -07:00
done_testing ;