2014-06-13 06:59:01 -07:00
#!/usr/bin/env perl
use strict ;
use warnings ;
2015-12-26 05:47:53 -08:00
use utf8 ;
2014-06-13 06:59:01 -07:00
use Test::More ;
2016-05-16 06:07:57 -07:00
use Test::Deep ;
2016-04-06 18:14:54 -07:00
use HTML::Entities ;
2014-06-13 06:59:01 -07:00
use DDG::Test::Goodie ;
zci answer_type = > 'encoded_url' ;
2014-09-27 06:42:57 -07:00
zci is_cached = > 1 ;
2014-06-13 06:59:01 -07:00
2015-12-27 00:49:40 -08:00
sub build_answer {
my ( $ answer , $ sub ) = @ _ ;
$ sub = '' unless $ sub ;
return sprintf ( "Percent-encoded URL: %s" , $ answer ) , structured_answer = > {
data = > {
2016-08-24 12:29:20 -07:00
title = > $ answer ,
subtitle = > "URL percent-encode: $sub"
2015-12-27 00:49:40 -08:00
} ,
templates = > {
group = > 'text' ,
moreAt = > 0
}
}
}
2014-06-13 06:59:01 -07:00
ddg_goodie_test (
2014-06-23 22:14:56 -07:00
[ qw( DDG::Goodie::URLEncode ) ] ,
2014-06-24 19:29:03 -07:00
# Primary example queries
2015-12-27 00:49:40 -08:00
'url encode https://duckduckgo.com/' = > test_zci ( build_answer ( 'https%3A%2F%2Fduckduckgo.com%2F' , 'https://duckduckgo.com/' ) ) ,
2016-06-10 01:50:21 -07:00
'uri encode https://duckduckgo.com/' = > test_zci ( build_answer ( 'https%3A%2F%2Fduckduckgo.com%2F' , 'https://duckduckgo.com/' ) ) ,
2015-12-27 00:49:40 -08:00
'encode url xkcd.com/blag' = > test_zci ( build_answer ( 'xkcd.com%2Fblag' , 'xkcd.com/blag' ) ) ,
2014-06-24 19:29:03 -07:00
2016-06-10 01:50:21 -07:00
'encode uri xkcd.com/blag' = > test_zci ( build_answer ( 'xkcd.com%2Fblag' , 'xkcd.com/blag' ) ) ,
2014-06-24 19:29:03 -07:00
# Secondary example queries
2015-12-27 00:49:40 -08:00
'http://arstechnica.com/ url escape' = > test_zci ( build_answer ( 'http%3A%2F%2Farstechnica.com%2F' , 'http://arstechnica.com/' ) ) ,
'apple.com/mac/ escape url' = > test_zci ( build_answer ( 'apple.com%2Fmac%2F' , 'apple.com/mac/' ) ) ,
'urlencode www.xkcd.com/a-webcomic-of-romance+math+sarcasm+language' = > test_zci ( build_answer ( 'www.xkcd.com%2Fa-webcomic-of-romance%2Bmath%2Bsarcasm%2Blanguage' , 'www.xkcd.com/a-webcomic-of-romance+math+sarcasm+language' ) ) ,
'https://example.com/zero#clickinfo^<goodies>;spice:fathead-\ encodeurl' = > test_zci ( build_answer ( 'https%3A%2F%2Fexample.com%2Fzero%23clickinfo%5E%3Cgoodies%3E%3Bspice%3Afathead-%5C' , 'https://example.com/zero#clickinfo^<goodies>;spice:fathead-\\' ) ) ,
'urlescape https://example.org/the answer to "[life], (the universe) .and. <everything>"' = > test_zci ( build_answer ( 'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22' , 'https://example.org/the answer to "[life], (the universe) .and. <everything>"' ) ) ,
'www.heroku.com/{rawwr!@#$%^&*()+=__} escapeurl' = > test_zci ( build_answer ( 'www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D' , 'www.heroku.com/{rawwr!@#$%^&*()+=__}' ) ) ,
'äöü escapeurl' = > test_zci ( build_answer ( '%E4%F6%FC' , 'äöü' ) ) ,
'hello there escapeurl' = > test_zci ( build_answer ( 'hello%20there' , 'hello there' ) ) ,
2014-06-13 06:59:01 -07:00
) ;
2016-05-16 06:18:04 -07:00
done_testing ;