From 86119c311e12235b63d47d51f07e1ea61e2f4ca9 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Mon, 16 May 2016 21:23:54 +0100 Subject: [PATCH 1/4] MagicEightBall: Converting to text template --- lib/DDG/Goodie/MagicEightBall.pm | 18 ++++++++------ t/MagicEightBall.t | 41 +++++++++++++------------------- 2 files changed, 27 insertions(+), 32 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/MagicEightBall.pm mode change 100644 => 100755 t/MagicEightBall.t diff --git a/lib/DDG/Goodie/MagicEightBall.pm b/lib/DDG/Goodie/MagicEightBall.pm old mode 100644 new mode 100755 index 18b370feb..164c25433 --- a/lib/DDG/Goodie/MagicEightBall.pm +++ b/lib/DDG/Goodie/MagicEightBall.pm @@ -10,7 +10,8 @@ zci is_cached => 0; triggers start => "magic eight ball", "magic 8 ball", "magic eight-ball", "magic 8-ball", "magic 8ball"; #These are the standard responses found in a magic eight ball -my @eightBallresponses = ("It is certain", +my @eightBallresponses = ( + "It is certain", "It is decidedly so", "Without a doubt", "Yes, definitely", @@ -39,12 +40,15 @@ handle remainder => sub { srand(); my $response = $eightBallresponses[int rand scalar @eightBallresponses]; - return $response, - structured_answer => { - input => [html_enc($_)], - operation => "Magic eight ball's answer to", - result => html_enc($response), - }; + return $response, structured_answer => { + data => { + title => html_enc($response), + subtitle => "Magic eight ball's answer to: ".html_enc($_) + }, + templates => { + group => 'text' + } + }; }; 1; diff --git a/t/MagicEightBall.t b/t/MagicEightBall.t old mode 100644 new mode 100755 index c91b67515..c6562f08b --- a/t/MagicEightBall.t +++ b/t/MagicEightBall.t @@ -11,34 +11,25 @@ zci is_cached => 0; my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/); -my $possibleStructuredAnswer = re(qr/^(?:It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)$/); +sub build_test +{ + my ($text, $input) = @_; + return test_zci($possibleAnswers, structured_answer =>{ + data => { + title => $possibleAnswers, + subtitle => "Magic eight ball's answer to: $input" + }, + templates => { + group => 'text' + } + }); +} ddg_goodie_test( [qw( DDG::Goodie::MagicEightBall )], - 'magic eight ball is it going to rain today' => test_zci( - $possibleAnswers, - structured_answer => { - input => ['is it going to rain today'], - operation => "Magic eight ball's answer to", - result => $possibleStructuredAnswer, - } - ), - 'magic 8 ball should I wear red today?' => test_zci( - $possibleAnswers, - structured_answer => { - input => ['should I wear red today?'], - operation => "Magic eight ball's answer to", - result => $possibleStructuredAnswer, - } - ), - 'magic eight-ball are you actually helpful' => test_zci( - $possibleAnswers, - structured_answer => { - input => ['are you actually helpful'], - operation => "Magic eight ball's answer to", - result => $possibleStructuredAnswer, - } - ), + 'magic eight ball is it going to rain today' => build_test($possibleAnswers, 'is it going to rain today'), + 'magic 8 ball should I wear red today?' => build_test($possibleAnswers, 'should I wear red today?'), + 'magic eight-ball are you actually helpful' => build_test($possibleAnswers, 'are you actually helpful'), 'eight ball will this work?' => undef, 'magic 8ball Yes?' => undef, 'magic 8ball' => undef From 32002f9c59ad6a4939f6a3287eed70ed2e713295 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Tue, 17 May 2016 08:14:39 +0100 Subject: [PATCH 2/4] MagicEightBall: Test Refactor --- t/MagicEightBall.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/MagicEightBall.t b/t/MagicEightBall.t index c6562f08b..7a602083a 100755 --- a/t/MagicEightBall.t +++ b/t/MagicEightBall.t @@ -13,7 +13,7 @@ my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Ye sub build_test { - my ($text, $input) = @_; + my ($input) = @_; return test_zci($possibleAnswers, structured_answer =>{ data => { title => $possibleAnswers, @@ -27,9 +27,9 @@ sub build_test ddg_goodie_test( [qw( DDG::Goodie::MagicEightBall )], - 'magic eight ball is it going to rain today' => build_test($possibleAnswers, 'is it going to rain today'), - 'magic 8 ball should I wear red today?' => build_test($possibleAnswers, 'should I wear red today?'), - 'magic eight-ball are you actually helpful' => build_test($possibleAnswers, 'are you actually helpful'), + 'magic eight ball is it going to rain today' => build_test('is it going to rain today'), + 'magic 8 ball should I wear red today?' => build_test('should I wear red today?'), + 'magic eight-ball are you actually helpful' => build_test('are you actually helpful'), 'eight ball will this work?' => undef, 'magic 8ball Yes?' => undef, 'magic 8ball' => undef From bd1e3afa92b2e1484af763cd83b66f0a1990cf1c Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Wed, 18 May 2016 12:43:13 +0100 Subject: [PATCH 3/4] MagicEightBall: Cuddling the sub --- t/MagicEightBall.t | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/MagicEightBall.t b/t/MagicEightBall.t index 7a602083a..41157b6ed 100755 --- a/t/MagicEightBall.t +++ b/t/MagicEightBall.t @@ -11,8 +11,7 @@ zci is_cached => 0; my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/); -sub build_test -{ +sub build_test { my ($input) = @_; return test_zci($possibleAnswers, structured_answer =>{ data => { From 8091fa7917ba78c6b0d50012c31d252de6d8d91e Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 22 May 2016 19:54:09 +0100 Subject: [PATCH 4/4] MagicEightBall: There's a chance it'll output the html output for one line containing a ' so I've made the regex match both --- t/MagicEightBall.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/MagicEightBall.t b/t/MagicEightBall.t index 41157b6ed..e0ab2b0e4 100755 --- a/t/MagicEightBall.t +++ b/t/MagicEightBall.t @@ -9,7 +9,7 @@ use DDG::Test::Goodie; zci answer_type => "magic_eight_ball"; zci is_cached => 0; -my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don't count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/); +my $possibleAnswers = re(qr/(It is certain|It is decidedly so|Without a doubt|Yes, definitely|You may rely on it|As I see it, yes|Most likely|Outlook good|Yes|Signs point to yes|Reply hazy try again|Ask again later|Better not tell you now|Cannot predict now|Concentrate and ask again|Don(?:'|')t count on it|My reply is no|My sources say no|Outlook not so good|Very doubtful)/); sub build_test { my ($input) = @_;