Skip to content

Commit

Permalink
Added t/free.t
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Mar 21, 2019
1 parent 50a8d31 commit 4a2b17d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Revision history for Geo-Coder-List

0.24
Support the cache option
Test Geo::Coder::Free::Local

0.23 Fri Feb 1 20:57:05 EST 2019
Add the calling line to the log
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if($ENV{AUTHOR_TESTING}) {
}

my $test_requires = {
'Test::Deep' => 0,
'Test::Most' => 0,
'Test::NoWarnings' => 0,
};
Expand Down
3 changes: 2 additions & 1 deletion lib/Geo/Coder/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ sub geocode {
POSSIBLE_LOCATION: foreach my $l(@rc) {
if(ref($l) eq 'ARRAY') {
# Geo::GeoNames
# TODO: should consider all locations in the array
# FIXME: should consider all locations in the array
$l = $l->[0];
}
if(!defined($l)) {
Expand All @@ -274,6 +274,7 @@ sub geocode {
next ENCODER;
}
print Data::Dumper->new([\$l])->Dump() if(DEBUG >= 2);
last if(ref($l) eq 'Geo::Location::Point');
next if(ref($l) ne 'HASH');
if($l->{'error'}) {
my $log = {
Expand Down
4 changes: 2 additions & 2 deletions t/critic.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use File::Spec;
use Test::Most;
use English qw(-no_match_vars);

unless($ENV{RELEASE_TESTING}) {
plan( skip_all => "Author tests not required for installation" );
unless($ENV{AUTHOR_TESTING}) {
plan(skip_all => 'Author tests not required for installation');
}

eval "use Test::Perl::Critic";
Expand Down
67 changes: 67 additions & 0 deletions t/free.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!perl -wT

use strict;
use warnings;
use Test::Most tests => 13;
use Test::NoWarnings;
use Test::Deep;

eval 'use autodie qw(:all)'; # Test for open/close failures

BEGIN {
use_ok('Geo::Coder::List');
}

FREE: {
SKIP: {
eval {
require Geo::Coder::Free;

Geo::Coder::Free->import();

require Geo::Coder::Free::Local;

Geo::Coder::Free::Local->import();

require Test::Number::Delta;

Test::Number::Delta->import();
};

if($@) {
diag('Geo::Coder::Free not installed - skipping tests');
skip 'Geo::Coder::Free not installed', 10;
} else {
diag("Using Geo::Coder::Free $Geo::Coder::Free::VERSION",
"/Geo::Coder::Free::Local $Geo::Coder::Free::Local::VERSION");
}
my $geo_coder_list = new_ok('Geo::Coder::List');
my $geo_coder_free = new_ok('Geo::Coder::Free');

$geo_coder_list->push({ regex => qr/,\s*(USA|US|United States|Canada|Australia)\s*$/, geocoder => $geo_coder_free })
->push({ regex => qr/^[\w\s\-]+?,[\w\s]+,[\w\s]+?$/, geocoder => $geo_coder_free })
# E.g. 'Nebraska, USA'
->push({ regex => qr/^[\w\s]+,\s*(UK|England|Canada|USA|US|United States)$/i, geocoder => $geo_coder_free })
->push({ regex => qr/^[\w\s]+,\s*[\w\s],\s*(UK|England|Wales|Scotland)$/i, geocoder => $geo_coder_free })
->push(new_ok('Geo::Coder::Free::Local'));

ok(!defined($geo_coder_list->geocode()));

cmp_deeply($geo_coder_list->geocode('NCBI, MEDLARS DR, BETHESDA, MONTGOMERY, MD, USA'),
methods('lat' => num(39.00, 1e-2), 'long' => num(-77.10, 1e-2)));

my $location = $geo_coder_list->geocode('1363 Kelly Road, Coal City, Owen, Indiana, USA');
ok(defined($location));
cmp_deeply($location,
methods('lat' => num(39.27, 1e-2), 'long' => num(-87.03, 1e-2)));
cmp_deeply($geo_coder_list->geocode('Woolwich, London, England'),
methods('lat' => num(51.47, 1e-2), 'long' => num(0.20, 1e-2)));
$location = $geo_coder_list->geocode(location => 'Margate, Kent, England');
ok(defined($location));
cmp_deeply($location,
methods('lat' => num(51.38, 1e-2), 'long' => num(1.39, 1e-2)));

cmp_deeply($geo_coder_list->geocode(location => 'Herne Bay, Kent, England'),
methods('lat' => num(51.38, 1e-2), 'long' => num(1.13, 1e-2)));
}
}

0 comments on commit 4a2b17d

Please sign in to comment.