Merge pull request #3089 from duckduckgo/mintsoft/MoonPhases

Moon Phases: Convert to structured answer
master
Ben Moon 2016-05-18 11:50:25 +01:00
commit c170b95b9e
2 changed files with 25 additions and 39 deletions

15
lib/DDG/Goodie/MoonPhases.pm Normal file → Executable file
View File

@ -55,12 +55,15 @@ handle query_lc => sub {
my $phaseUrl = $phase;
$phaseUrl =~ s/\s+/+/g;
return "The current lunar phase is: $phase",
structured_answer => {
input => [],
result => $phase,
operation => 'Current lunar phase'
};
return "The current lunar phase is: $phase", structured_answer => {
data => {
title => $phase,
subtitle => 'Current lunar phase'
},
templates => {
group => 'text'
}
};
};

49
t/MoonPhases.t Normal file → Executable file
View File

@ -16,42 +16,25 @@ my $named = qr/(?:New|Full)$space_plus(?:Moon)/;
my $phases = qr/$wax_wane|$quarter|$named/;
my $ascii_answer = re(qr/^The current lunar phase is: $phases$/);
my $html_answer = re(qr%^The current lunar phase is: <a href="\?q=$phases">$phases</a>$%);
sub build_test {
return test_zci($ascii_answer, structured_answer => {
data => {
title => re($phases),
subtitle => 'Current lunar phase'
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test(
[qw( DDG::Goodie::MoonPhases)],
'moon phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'Current lunar phase',
result => re($phases),
}
),
'lunar phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'Current lunar phase',
result => re($phases),
}
),
'phase of the moon' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'Current lunar phase',
result => re($phases),
}
),
'what is the current lunar phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'Current lunar phase',
result => re($phases),
}
),
'moon phase' => build_test(),
'lunar phase' => build_test(),
'phase of the moon' => build_test(),
'what is the current lunar phase' => build_test()
);
done_testing;