From 5121d7536fc3931738438df6d452ef3d943b9782 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 1 Oct 2014 09:47:08 +0200 Subject: [PATCH] SunInfo: allow for question-form queries. Also, add some more negative tests. --- lib/DDG/Goodie/SunInfo.pm | 5 +++-- t/SunInfo.t | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/DDG/Goodie/SunInfo.pm b/lib/DDG/Goodie/SunInfo.pm index 87b6e68c3..2e1157508 100644 --- a/lib/DDG/Goodie/SunInfo.pm +++ b/lib/DDG/Goodie/SunInfo.pm @@ -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. diff --git a/t/SunInfo.t b/t/SunInfo.t index 2ecc6707d..e772684b7 100644 --- a/t/SunInfo.t +++ b/t/SunInfo.t @@ -20,14 +20,20 @@ ddg_goodie_test([qw( DDG::Goodie::SunInfo ) ], - 'sunrise' => test_zci(@now), - 'sunset' => test_zci(@now), - 'sunrise 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), - 'sunset for pilly' => undef, - 'sunrise on mars' => undef, + '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 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;