PhoneAlphabet: Converting to text template

master
Rob Emery 2016-05-18 13:26:47 +01:00
parent 04a6925302
commit ebd008fe04
2 changed files with 26 additions and 50 deletions

View File

@ -22,11 +22,14 @@ handle remainder => sub {
# Use a regex to replace each letter with the corresponding number from the phone key pad. # Use a regex to replace each letter with the corresponding number from the phone key pad.
$num =~ tr/abcdefghijklmnopqrstuvwxyz/22233344455566677778889999/; $num =~ tr/abcdefghijklmnopqrstuvwxyz/22233344455566677778889999/;
return "Phone Number: $num", return "Phone Number: $num", structured_answer => {
structured_answer => { data => {
input => [html_enc($input)], title => $num,
operation => "Phone Number", subtitle => "Phone Number: ".html_enc($input)
result => "$num", },
templates => {
group => 'text'
}
}; };
}; };

View File

@ -9,53 +9,26 @@ use DDG::Test::Goodie;
zci answer_type => "phone_alphabet"; zci answer_type => "phone_alphabet";
zci is_cached => 1; zci is_cached => 1;
sub build_test {
my($text, $input, $number) = @_;
return test_zci($text, structured_answer => {
data => {
title => $number,
subtitle => "Phone Number: $input"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test( ddg_goodie_test(
[qw( DDG::Goodie::PhoneAlphabet )], [qw( DDG::Goodie::PhoneAlphabet )],
'1-800-LAWYR-UP to digits' => test_zci( '1-800-LAWYR-UP to digits' => build_test('Phone Number: 1-800-52997-87', '1-800-LAWYR-UP', '1-800-52997-87'),
'Phone Number: 1-800-52997-87', '1-800-fun-hack to phone number' => build_test('Phone Number: 1-800-386-4225', '1-800-fun-hack', '1-800-386-4225'),
structured_answer => { '1-800-fun-hack to numbers' => build_test('Phone Number: 1-800-386-4225', '1-800-fun-hack', '1-800-386-4225'),
input => ['1-800-LAWYR-UP'], '1958funhack to phone' => build_test('Phone Number: 19583864225', '1958funhack', '19583864225'),
operation => 'Phone Number', '13TAXI to phone' => build_test('Phone Number: 138294', '13TAXI', '138294'),
result => '1-800-52997-87'
}
),
'1-800-fun-hack to phone number' => test_zci(
'Phone Number: 1-800-386-4225',
structured_answer => {
input => ['1-800-fun-hack'],
operation => 'Phone Number',
result => '1-800-386-4225'
}
),
'1-800-fun-hack to numbers' => test_zci(
'Phone Number: 1-800-386-4225',
structured_answer => {
input => ['1-800-fun-hack'],
operation => 'Phone Number',
result => '1-800-386-4225'
}
),
'1958funhack to phone' => test_zci(
'Phone Number: 19583864225',
structured_answer => {
input => ['1958funhack'],
operation => 'Phone Number',
result => '19583864225'
}
),
'13TAXI to phone' => test_zci(
'Phone Number: 138294',
structured_answer => {
input => ['13TAXI'],
operation => 'Phone Number',
result => '138294'
}
),
'something fun to hack to phone' => undef, 'something fun to hack to phone' => undef,
'0x0123 to digits' => undef '0x0123 to digits' => undef
); );