From 463027d8963aa861897765f1d3e4de0822d073fd Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Tue, 17 May 2016 21:18:02 +0100 Subject: [PATCH] PaleoIngredientCheck: Converting to text template --- lib/DDG/Goodie/PaleoIngredientCheck.pm | 13 +++--- t/PaleoIngredientCheck.t | 58 ++++++++------------------ 2 files changed, 26 insertions(+), 45 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/PaleoIngredientCheck.pm mode change 100644 => 100755 t/PaleoIngredientCheck.t diff --git a/lib/DDG/Goodie/PaleoIngredientCheck.pm b/lib/DDG/Goodie/PaleoIngredientCheck.pm old mode 100644 new mode 100755 index 23260e42d..e0c4a93a9 --- a/lib/DDG/Goodie/PaleoIngredientCheck.pm +++ b/lib/DDG/Goodie/PaleoIngredientCheck.pm @@ -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' + } }; }; diff --git a/t/PaleoIngredientCheck.t b/t/PaleoIngredientCheck.t old mode 100644 new mode 100755 index a06a4921b..d42579b58 --- a/t/PaleoIngredientCheck.t +++ b/t/PaleoIngredientCheck.t @@ -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,