Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Feb 16, 2016
1 parent bad1343 commit 627b9d8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
6 changes: 2 additions & 4 deletions lib/DDG/Spice/SkiResorts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ my $data = share('resorts.json')->slurp;
my @resorts = @{decode_json($data)};
@resorts = map { $_ =~s/-/ /g; $_; } @resorts; # Replace dashes with spaces

# Define triggers
# Define triggers (will only trigger in conjustion with resort name, e.g. Ski Heavenly)
triggers startend => "ski", "skiing", "ski conditions at", "snowboarding", "map", "piste map", "resort map";
#triggers start => "ski conditions at";

# Handle statement
handle remainder => sub {
# Find first matching resort
my $resort = '';
foreach my $i (0..$#resorts) {
next if $_ !~ /$resorts[$i]/;
next if $_ !~ /$resorts[$i]/i;
$resort = $resorts[$i];
$resort =~ s/\s/-/g; # Replace spaces with dashes
last; # Have match, exit
}

# If we have a match trigger, otherwise discard (by not returning)
return unless $resort;
};

Expand Down
51 changes: 44 additions & 7 deletions t/SkiResorts.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,64 @@ spice is_cached => 1;
ddg_spice_test(
[qw( DDG::Spice::SkiResorts)],
# Valid queries
'Chamonix' => test_spice(
'/js/spice/ski_resorts/Chamonix',
'ski Chamonix' => test_spice(
'/js/spice/ski_resorts/chamonix',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'Mayrhofen' => test_spice(
'/js/spice/ski_resorts/Mayrhofen',
'ski chamonix' => test_spice(
'/js/spice/ski_resorts/chamonix',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'St Anton' => test_spice(
'/js/spice/ski_resorts/St-Anton',
'Mayrhofen piste map' => test_spice(
'/js/spice/ski_resorts/mayrhofen',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'ski conditions at Zugspitze' => test_spice(
'/js/spice/ski_resorts/zugspitze',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'St Anton skiing' => test_spice(
'/js/spice/ski_resorts/st-anton',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'ski in Chamonix' => test_spice(
'/js/spice/ski_resorts/chamonix',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'Adelboden resort map' => test_spice(
'/js/spice/ski_resorts/adelboden',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'piste map Adelboden' => test_spice(
'/js/spice/ski_resorts/adelboden',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
'snowboarding St Anton' => test_spice(
'/js/spice/ski_resorts/st-anton',
call_type => 'include',
caller => 'DDG::Spice::SkiResorts',
is_cached => 1
),
# Invalid queries
'Fish' => undef,
'Morzine' => undef,
'London' => undef,
'skiing in London' => undef,
'Mountain' => undef
);

Expand Down

0 comments on commit 627b9d8

Please sign in to comment.