Convert CountryCodes to full template goodie (#3037)
Goodies have full support for templates, and it'd be great to make sure that all goodies use full templates. The "simple structured_answer" was provided as a temporary workaround. * change to 'text' template for structured_answer object * refactored test suite See also: Updates CountryCodes Goodie Re: #2767master
parent
435480ab73
commit
a426dccaf5
|
@ -36,9 +36,13 @@ handle remainder => sub {
|
|||
|
||||
return 'ISO 3166: '. ucfirst $input .' - '. $answer[0],
|
||||
structured_answer => {
|
||||
input => [ucfirst $input],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => ($answer[0]),
|
||||
data => {
|
||||
title => $answer[0],
|
||||
subtitle => "ISO 3166 Country code: " . ucfirst ($input)
|
||||
},
|
||||
templates => {
|
||||
group => "text"
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
137
t/CountryCodes.t
137
t/CountryCodes.t
|
@ -9,116 +9,39 @@ use DDG::Test::Goodie;
|
|||
zci answer_type => "country_codes";
|
||||
zci is_cached => 1;
|
||||
|
||||
my $text = '</div><div class="zci__subheader">ISO 3166 Country code for';
|
||||
sub build_structured_answer{
|
||||
my ($country, $response) = @_;
|
||||
return 'ISO 3166: '. ucfirst $country .' - '. $response,
|
||||
structured_answer => {
|
||||
data => {
|
||||
title => $response,
|
||||
subtitle => "ISO 3166 Country code: " . ucfirst ($country),
|
||||
},
|
||||
templates => {
|
||||
group => "text",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sub build_test { test_zci(build_structured_answer(@_)) }
|
||||
|
||||
ddg_goodie_test(
|
||||
[ 'DDG::Goodie::CountryCodes' ],
|
||||
"country code Japan" => test_zci(
|
||||
qq(ISO 3166: Japan - jp),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jp'
|
||||
}
|
||||
),
|
||||
"3 letter country code Japan" => test_zci(
|
||||
qq(ISO 3166: Japan - jpn),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jpn'
|
||||
}
|
||||
),
|
||||
"3 letter country code of China" => test_zci(
|
||||
qq(ISO 3166: China - chn),
|
||||
structured_answer => {
|
||||
input => ['China'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'chn'
|
||||
}
|
||||
),
|
||||
"Japan 3 letter country code" => test_zci(
|
||||
qq(ISO 3166: Japan - jpn),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jpn'
|
||||
}
|
||||
),
|
||||
"Russia two letter country code" => test_zci(
|
||||
qq(ISO 3166: Russia - ru),
|
||||
structured_answer => {
|
||||
input => ['Russia'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'ru'
|
||||
}
|
||||
),
|
||||
"two letter country code Japan" => test_zci(
|
||||
qq(ISO 3166: Japan - jp),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jp'
|
||||
}
|
||||
),
|
||||
"three letter country code for Japan" => test_zci(
|
||||
qq(ISO 3166: Japan - jpn),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jpn'
|
||||
}
|
||||
),
|
||||
"numerical iso code japan" => test_zci(
|
||||
qq(ISO 3166: Japan - 392),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => '392'
|
||||
}
|
||||
),
|
||||
"iso code for spain" => test_zci(
|
||||
qq(ISO 3166: Spain - es),
|
||||
structured_answer => {
|
||||
input => ['Spain'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'es'
|
||||
}
|
||||
),
|
||||
"country code jp" => test_zci(
|
||||
qq(ISO 3166: Japan - jp),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'jp'
|
||||
}
|
||||
),
|
||||
"japan numerical iso 3166" => test_zci(
|
||||
qq(ISO 3166: Japan - 392),
|
||||
structured_answer => {
|
||||
input => ['Japan'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => '392'
|
||||
}
|
||||
),
|
||||
"united states of america iso code" => test_zci(
|
||||
qq(ISO 3166: United states of america - us),
|
||||
structured_answer => {
|
||||
input => ['United states of america'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'us'
|
||||
}
|
||||
),
|
||||
"3 letter iso code isle of man" => test_zci(
|
||||
qq(ISO 3166: Isle of man - imn),
|
||||
structured_answer => {
|
||||
input => ['Isle of man'],
|
||||
operation => 'ISO 3166 Country code',
|
||||
result => 'imn'
|
||||
}
|
||||
),
|
||||
'country code for gelgamek' => undef,
|
||||
'iso code for english' => undef,
|
||||
"country code Japan" => build_test("Japan","jp"),
|
||||
"3 letter country code Japan" => build_test("Japan","jpn"),
|
||||
"3 letter country code of China" => build_test("China","chn"),
|
||||
"Japan 3 letter country code" => build_test("Japan","jpn"),
|
||||
"Russia two letter country code" => build_test("Russia","ru"),
|
||||
"two letter country code Japan" => build_test("Japan","jp"),
|
||||
"three letter country code for Japan" => build_test("Japan","jpn"),
|
||||
"numerical iso code japan" => build_test("Japan",392),
|
||||
"iso code for spain" => build_test("Spain","es"),
|
||||
"country code jp" => build_test("Japan","jp"),
|
||||
"japan numerical iso 3166" => build_test("Japan",392),
|
||||
"united states of america iso code" => build_test("United states of america","us"),
|
||||
"3 letter iso code isle of man" => build_test("Isle of man","imn"),
|
||||
'country code for gelgamek' => undef,
|
||||
'iso code for english' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue