Geo-Coder-Free
view release on metacpan or search on metacpan
lib/Geo/Coder/Free.pm view on Meta::CPAN
# Geo::Coder::Free::<name> by t/function.t, t/path.t and t/edge_cases.t.
use namespace::clean -except => [qw(_valid_location _normalize _abbreviate)];
# TODO: from the 0.50 gap analysis
#
# Errors and housekeeping:
# TODO: xt/mutant_*.t stubs are committed by CI with 117 TODOs, against
# their own "DO NOT COMMIT" header; complete them or stop committing them
#
# Waiting on VWF master (each has a TODO block in t/domain.t):
# TODO: in VWF master, for Utils::distance: NaN gets past the range check and
# dies in Math::Complex, and a unit of "K\n" or "N\n" gets past the unit
# check and answers in miles
#
# Coverage and testing:
# TODO: ship a small fixture openaddresses.sql and cities.sql so t/openaddr.t
# and t/maxmind.t run in CI. CI branch coverage is 10.6% for
# OpenAddresses.pm and 26.9% for MaxMind.pm because neither database is there
# TODO: accuracy tests - a table of well-known cities checked to within a
# tolerance with Utils::distance(), which would have caught the
# "City, Country" bug below
throws_ok { distance(@args) } $error, "invalid: $name just past the edge, $outside";
}
foreach my $bad([ undef, qr/^$name must be defined/ ], [ 'abc', qr/^$name must be numeric/ ], [ '', qr/^$name must be numeric/ ], [ "\x{fc}", qr/^$name must be numeric/ ], [ 'Inf', $error ], [ '-Inf', $error ]) {
my @args = @base;
$args[$index] = $bad->[0];
throws_ok { distance(@args) } $bad->[1], "invalid: $name is " . _show($bad->[0]);
}
TODO: {
local $TODO = 'NaN looks like a number and compares false, so it passes the range check and dies in Math::Complex';
my @args = @base;
$args[$index] = 'NaN';
throws_ok { distance(@args) } $error, "invalid: $name is NaN";
}
}
foreach my $numeric([ '1e1', 'an exponent' ], [ ' 1', 'a leading space' ], [ "1\n", 'a trailing newline' ], [ '+1', 'a leading plus' ], [ '.5', 'no digit before the point' ]) {
lives_ok { distance($numeric->[0], 0, 0, 0) } "valid: $numeric->[1], which looks like a number";
}
throws_ok { distance(0, 0, 1) } qr/Too few arguments/, 'invalid: three coordinates';
throws_ok { distance(0, 0, 1, 1, 'K', 'extra') } qr/Too many arguments/, 'invalid: six arguments';
};
t/edge_cases.t view on Meta::CPAN
LAT_MIN => -90,
LON_MAX => 180,
LON_MIN => -180,
# Alarm timeout for ReDoS regression tests (seconds).
REDOS_TIMEOUT => 5,
};
# -----------------------------------------------------------------------
# 1. Utils::distance â undef / missing coordinates
# Strategy: each null argument slot should trigger a distinct croak
# rather than silently producing 0 or NaN.
# -----------------------------------------------------------------------
subtest 'distance() â null/undef coordinates croak' => sub {
throws_ok { Geo::Coder::Free::Utils::distance(undef, 0, 0, 0 ) } qr/lat1 must be defined/, 'undef lat1';
throws_ok { Geo::Coder::Free::Utils::distance(0, undef, 0, 0 ) } qr/lon1 must be defined/, 'undef lon1';
throws_ok { Geo::Coder::Free::Utils::distance(0, 0, undef, 0 ) } qr/lat2 must be defined/, 'undef lat2';
throws_ok { Geo::Coder::Free::Utils::distance(0, 0, 0, undef) } qr/lon2 must be defined/, 'undef lon2';
};
# -----------------------------------------------------------------------
# 2. Utils::distance â non-numeric coordinates
( run in 2.712 seconds using v1.01-cache-2.11-cpan-60884a8df76 )