PaleoIngredientCheck: Converting to text template

master
Rob Emery 2016-05-17 21:18:02 +01:00
parent 24755a1018
commit 463027d896
2 changed files with 26 additions and 45 deletions

13
lib/DDG/Goodie/PaleoIngredientCheck.pm Normal file → Executable file
View File

@ -38,11 +38,14 @@ handle remainder => sub {
return unless $result; # ensure we have a result
return $result,
structured_answer => {
input => [$item], # or just the original query
operation => "Paleo Friendly",
result => $result
return $result, structured_answer => {
data => {
title => $result,
subtitle => "Paleo Friendly: $item"
},
templates => {
group => 'text'
}
};
};

58
t/PaleoIngredientCheck.t Normal file → Executable file
View File

@ -9,48 +9,26 @@ use DDG::Test::Goodie;
zci answer_type => "paleo_ingredient_check";
zci is_cached => 1;
sub build_test {
my ($text, $input) = @_;
return test_zci($text, structured_answer =>{
data => {
title => $text,
subtitle => "Paleo Friendly: $input"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test(
[qw( DDG::Goodie::PaleoIngredientCheck )],
'are apples paleo friendly' => test_zci(
'Yes',
structured_answer => {
input => ['apples'],
operation => 'Paleo Friendly',
result => 'Yes',
},
),
'Is dairy allowed on the paleo diet?' => test_zci(
'No',
structured_answer => {
input => ['dairy'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'Is sugar paleo friendly?' => test_zci(
'No',
structured_answer => {
input => ['sugar'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'beans paleo safe' => test_zci(
'No',
structured_answer => {
input => ['beans'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'is sugar paleo' => test_zci(
'No',
structured_answer => {
input => ['sugar'],
operation => 'Paleo Friendly',
result => 'No',
},
),
'are apples paleo friendly' => build_test('Yes', "apples"),
'Is dairy allowed on the paleo diet?' => build_test('No', "dairy"),
'Is sugar paleo friendly?' => build_test("No", "sugar"),
'beans paleo safe' => build_test("No", "beans"),
'is sugar paleo' => build_test("No", "sugar"),
'Is foobar allowed on the paleo diet?' => undef,
'are notarealfood paleo friendly' => undef,
'paleo diet recipes' => undef,