File: live.t

package info (click to toggle)
libgeo-coder-osm-perl 0.03-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 122; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,927 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;
use Encode;
use Geo::Coder::OSM;
use LWP::UserAgent;
use Test::More;

my $debug = $ENV{GEO_CODER_OSM_DEBUG};
diag "Set GEO_CODER_OSM_DEBUG to see request/response data"
    unless $debug;

for my $source (qw(osm mapquest)) {
    my $geocoder = Geo::Coder::OSM->new(
        debug   => $debug,
        sources => $source,
    );
    {
        my $address = '132 Maney Hill Road, West Midlands, UK';
        my $forward = $geocoder->geocode($address);
        is(
            $forward->{address}{town},
            'Sutton Coldfield',
            "correct town for $address"
        );
        my $road = $forward->{address}{road};

        my ($lat, $lon) = @$forward{qw(lat lon)};
        my $reverse = $geocoder->reverse_geocode(lat => $lat, lon => $lon);
        is(
            $reverse->{address}{road},
            $forward->{address}{road},
            'correct street for lat/lon',
        );
    }
    {
        my $address = qq(Champs-\xC9lys\xE9es, 75008);

        my $location = $geocoder->geocode($address);
        ok($location, 'latin1 bytes');
        is($location->{address}{country}, 'France', 'latin1 bytes');

        $location = $geocoder->geocode(decode('latin1', $address));
        ok($location, 'UTF-8 characters');
        is($location->{address}{country}, 'France', 'UTF-8 characters');

        TODO: {
            local $TODO = 'UTF-8 bytes';
            $location = $geocoder->geocode(
                encode('utf-8', decode('latin1', $address))
            );
            ok($location, 'UTF-8 bytes');
            is($location->{address}{country}, 'France', 'UTF-8 bytes');
        }
    }
    {
        my $city = decode('latin1', qq(Schm\xF6ckwitz));
        my $location = $geocoder->geocode("$city, Berlin, Germany");
        is(
            $location->{address}{suburb}, $city,
            'decoded character encoding of response'
        );
    }
}

done_testing;