Merge pull request #3077 from duckduckgo/mintsoft-magiceightball

MagicEightBall: Converting to text template
master
Ben Moon 2016-05-23 12:03:30 +01:00
commit 77f79c3e77
2 changed files with 27 additions and 33 deletions

18
lib/DDG/Goodie/MagicEightBall.pm Normal file → Executable file
View File

@ -10,7 +10,8 @@ zci is_cached => 0;
triggers start => "magic eight ball", "magic 8 ball", "magic eight-ball", "magic 8-ball", "magic 8ball"; 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 #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", "It is decidedly so",
"Without a doubt", "Without a doubt",
"Yes, definitely", "Yes, definitely",
@ -39,12 +40,15 @@ handle remainder => sub {
srand(); srand();
my $response = $eightBallresponses[int rand scalar @eightBallresponses]; my $response = $eightBallresponses[int rand scalar @eightBallresponses];
return $response, return $response, structured_answer => {
structured_answer => { data => {
input => [html_enc($_)], title => html_enc($response),
operation => "Magic eight ball's answer to", subtitle => "Magic eight ball's answer to: ".html_enc($_)
result => html_enc($response), },
}; templates => {
group => 'text'
}
};
}; };
1; 1;

42
t/MagicEightBall.t Normal file → Executable file
View File

@ -9,36 +9,26 @@ use DDG::Test::Goodie;
zci answer_type => "magic_eight_ball"; zci answer_type => "magic_eight_ball";
zci is_cached => 0; 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)/);
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 ($input) = @_;
return test_zci($possibleAnswers, structured_answer =>{
data => {
title => $possibleAnswers,
subtitle => "Magic eight ball's answer to: $input"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test( ddg_goodie_test(
[qw( DDG::Goodie::MagicEightBall )], [qw( DDG::Goodie::MagicEightBall )],
'magic eight ball is it going to rain today' => test_zci( 'magic eight ball is it going to rain today' => build_test('is it going to rain today'),
$possibleAnswers, 'magic 8 ball should I wear red today?' => build_test('should I wear red today?'),
structured_answer => { 'magic eight-ball are you actually helpful' => build_test('are you actually helpful'),
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,
}
),
'eight ball will this work?' => undef, 'eight ball will this work?' => undef,
'magic 8ball Yes?' => undef, 'magic 8ball Yes?' => undef,
'magic 8ball' => undef 'magic 8ball' => undef