SunInfo: allow for question-form queries.

Also, add some more negative tests.
master
Matt Miller 2014-10-01 09:47:08 +02:00
parent dc15d8cb83
commit 5121d7536f
2 changed files with 17 additions and 10 deletions

View File

@ -10,7 +10,7 @@ use Try::Tiny;
zci answer_type => "sun_info";
zci is_cached => 0;
triggers start => 'sunrise', 'sunset';
triggers start => 'sunrise', 'sunset', 'what time is sunset', 'what time is sunrise';
primary_example_queries 'sunrise', 'sunset';
secondary_example_queries 'sunrise for aug 30', 'sunset on 2015-01-01';
@ -25,7 +25,8 @@ my $datestring_regex = datestring_regex();
handle remainder => sub {
my $remainder = shift;
my $remainder = shift // '';
$remainder =~ s/\?//g; # Strip question marks.
my ($lat, $lon, $tz) = ($loc->latitude, $loc->longitude, $loc->time_zone);
my $where = join(', ', grep { defined $_ } ($loc->city, $loc->region_name, $loc->country_name));
return unless (($lat || $lon) && $tz && $where); # We'll need a real location and time zone.

View File

@ -21,13 +21,19 @@ ddg_goodie_test([qw(
)
],
'sunrise' => test_zci(@now),
'what time is sunrise' => test_zci(@now),
'sunset' => test_zci(@now),
'what time is sunset' => test_zci(@now),
'sunrise for aug 30' => test_zci(@aug),
'sunset for aug 30' => test_zci(@aug),
'sunset for aug 30?' => test_zci(@aug),
'sunset on 2015-01-01' => test_zci(@exact),
'sunrise on 2015-01-01' => test_zci(@exact),
'what time is sunrise on 2015-01-01?' => test_zci(@exact),
'sunset for pilly' => undef,
'sunrise on mars' => undef,
'sunset boulevard' => undef,
'tequila sunrise' => undef,
'sunrise mall' => undef,
'after the sunset' => undef,
);
done_testing;