Phonetic: Convert to structured (#4354)
* Make phonetic goodies structured * add title/subtitle format * switch title and subtitle * fix testsmaster
parent
a2b28cba96
commit
a6bbd9c176
|
@ -57,7 +57,18 @@ handle remainder => sub {
|
|||
$_ = lc;
|
||||
my @words = split(/\s+/, $_);
|
||||
my @phonetics = map { components($_) } @words;
|
||||
return "Phonetic: " . join(" ", @phonetics);
|
||||
my $string_answer = "Phonetic: " . join(" ", @phonetics);
|
||||
my $title = join(" ", @phonetics);
|
||||
my $subtitle = "Phonetic: " . $_;
|
||||
return $string_answer, structured_answer => {
|
||||
data => {
|
||||
title => $title,
|
||||
subtitle => $subtitle,
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
25
t/Phonetic.t
25
t/Phonetic.t
|
@ -9,14 +9,31 @@ use DDG::Test::Goodie;
|
|||
zci answer_type => 'phonetic';
|
||||
zci is_cached => 1;
|
||||
|
||||
sub build_answer {
|
||||
my($word, $answer) = @_;
|
||||
return "Phonetic: " . $answer,
|
||||
structured_answer => {
|
||||
data => {
|
||||
title => $answer,
|
||||
subtitle => "Phonetic: " . $word,
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
sub build_test { test_zci(build_answer(@_)) }
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::Phonetic
|
||||
)],
|
||||
'phonetic what duck' => test_zci('Phonetic: Whiskey-Hotel-Alfa-Tango Delta-Uniform-Charlie-Kilo'),
|
||||
'phonetic through yonder' => test_zci('Phonetic: Tango-Hotel-Romeo-Oscar-Uniform-Golf-Hotel Yankee-Oscar-November-Delta-Echo-Romeo'),
|
||||
'phonetic window quacks' => test_zci('Phonetic: Whiskey-India-November-Delta-Oscar-Whiskey Quebec-Uniform-Alfa-Charlie-Kilo-Sierra'),
|
||||
'phonetic Who are you?' => test_zci('Phonetic: Whiskey-Hotel-Oscar Alfa-Romeo-Echo Yankee-Oscar-Uniform')
|
||||
'phonetic what duck' => build_test('what duck', 'Whiskey-Hotel-Alfa-Tango Delta-Uniform-Charlie-Kilo'),
|
||||
'phonetic through yonder' => build_test('through yonder', 'Tango-Hotel-Romeo-Oscar-Uniform-Golf-Hotel Yankee-Oscar-November-Delta-Echo-Romeo'),
|
||||
'phonetic window quacks' => build_test('window quacks', 'Whiskey-India-November-Delta-Oscar-Whiskey Quebec-Uniform-Alfa-Charlie-Kilo-Sierra'),
|
||||
'phonetic Who are you?' => build_test('who are you?', 'Whiskey-Hotel-Oscar Alfa-Romeo-Echo Yankee-Oscar-Uniform'),
|
||||
'what is phonetic?' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue