diff --git a/lib/DDG/Goodie/Phonetic.pm b/lib/DDG/Goodie/Phonetic.pm index e308f3a1f..e80f37fe3 100644 --- a/lib/DDG/Goodie/Phonetic.pm +++ b/lib/DDG/Goodie/Phonetic.pm @@ -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; diff --git a/t/Phonetic.t b/t/Phonetic.t index b74536249..fab8f30d8 100644 --- a/t/Phonetic.t +++ b/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;