-
Notifications
You must be signed in to change notification settings - Fork 1
/
live.t
105 lines (89 loc) · 2.69 KB
/
live.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use strict;
use warnings;
use Encode qw(decode encode);
use Geo::Coder::Mapquest;
use LWP::UserAgent;
use Test::More;
plan skip_all => 'MAPQUEST_APIKEY environment variable must be set'
unless $ENV{MAPQUEST_APIKEY};
my $debug = $ENV{GEO_CODER_MAPQUEST_DEBUG};
diag "Set GEO_CODER_MAPQUEST_DEBUG to see request/response data"
unless $debug;
my $has_ssl = LWP::UserAgent->is_protocol_supported('https');
my $open = 0;
GOTO:
my $geocoder = Geo::Coder::Mapquest->new(
apikey => $ENV{MAPQUEST_APIKEY},
open => $open,
debug => $debug,
);
{
my $address = 'Hollywood & Highland, Los Angeles, CA';
my $location = $geocoder->geocode($address);
is($location->{postalCode}, 90028, "correct zip code for $address");
}
{
my @locations = $geocoder->geocode('Main Street, Los Angeles, CA');
ok(@locations > 1, 'there are many Main Streets in Los Angeles, CA');
}
{
my $address = qq(Ch\xE2teau d Uss\xE9, 37420);
my $location = $geocoder->geocode($address, country => 'FR');
ok($location, 'latin1 bytes');
TODO: {
local $TODO = 'International locations';
is($location->{adminArea1}, 'FR', 'latin1 bytes');
}
$location = $geocoder->geocode(
location => decode('latin1', $address),
country => 'FR'
);
ok($location, 'UTF-8 characters');
TODO: {
local $TODO = 'International locations';
is($location->{adminArea1}, 'FR', 'UTF-8 characters');
}
$location = $geocoder->geocode(
location => encode('utf-8', decode('latin1', $address)),
country => 'FR',
);
ok($location, 'UTF-8 bytes');
TODO: {
local $TODO = 'International locations';
is($location->{adminArea1}, 'FR', 'UTF-8 bytes');
}
}
my @addresses = (
'Los Liones Dr, Pacific Palisades, CA 90272',
'2001 North Fuller Avenue, Los Angeles, CA',
'4730 Crystal Springs Drive, Los Angeles, CA',
);
{
my @locations = $geocoder->batch(\@addresses);
is(@locations, 3, 'batch - number of results');
for my $i (0..2) {
is(
$locations[$i]->[0]{providedLocation},
$addresses[$i], 'batch - result ' . ($i+1)
);
}
}
SKIP: {
skip 'no SSL support', 1 unless $has_ssl;
my $geocoder = Geo::Coder::Mapquest->new(
apikey => $ENV{MAPQUEST_APIKEY},
https => 1,
debug => $debug,
);
my $address = 'Hollywood & Highland, Los Angeles, CA';
my $location = $geocoder->geocode($address);
is($location->{postalCode}, 90028, 'https geocode');
my @locations = $geocoder->batch(\@addresses);
is(@locations, 3, 'https batch');
}
unless ($open) {
diag 'Testing opendata server';
$open = 1;
goto 'GOTO';
}
done_testing;