1.54KiB; Perl | 2020-10-05 02:26:38+02 | Statements 35 | SLOC 54
1
#!perl -w
2
3
use strict;
4
use warnings;
5
use Test::Most tests => 17;
6
use Test::NoWarnings;
7
8
BEGIN {
9
	use_ok('Geo::Coder::Abbreviations');
10
}
11
12
BASICS: {
13
	SKIP: {
14
		skip 'Test requires Internet access', 15 unless(-e 't/online.enabled');
15
		if(my $abbr = new_ok('Geo::Coder::Abbreviations')) {
16
			ok($abbr->abbreviate('Road') eq 'RD');
17
			ok($abbr->abbreviate('Avenue') eq 'AV');	# I think it should abbreviate to AVE
18
19
			my %streets = (
20
				'SW MACVICAR AVENUE' => 'SW MACVICAR AV',
21
				'NORFOLK AVENUE' => 'NORFOLK AV',
22
				'CONNECTICUT AVENUE' => 'CONNECTICUT AV',
23
				'HOWARD AVENUE' => 'HOWARD AV',
24
				'MAPLE AVENUE W' => 'MAPLE AV W',
25
				'SW MACVICAR AVE' => 'SW MACVICAR AV',
26
				'NORFOLK AVE' => 'NORFOLK AV',
27
				'CONNECTICUT AVE' => 'CONNECTICUT AV',
28
				'HOWARD AVE' => 'HOWARD AV',
29
				'MAPLE AVE W' => 'MAPLE AV W',
30
				'HIGH STREET' => 'HIGH ST',
31
				'HIGH ST' => 'HIGH ST',
32
			);
33
34
			while ((my ($k, $v)) = each(%streets)) {
35
				my $street = uc($k);
36
				if($street =~ /(.+)\s+(.+)\s+(.+)/) {
37
					my $a;
38 1
					if($a = $abbr->abbreviate($2)) {
39
						$street = "$1 $a $3";
40
					} elsif($a = $abbr->abbreviate($3)) {
41
						$street = "$1 $2 $a";
42
					}
43
				} elsif($street =~ /(.+)\s(.+)$/) {
44 1
					if(my $a = $abbr->abbreviate($2)) {
45
						$street = "$1 $a";
46
					}
47
				}
48
				# $street =~ s/^0+//;	# Turn 04th St into 4th St
49
				diag("$k: expected $v, got $street") if($street ne $v);
50
				ok($street eq $v);
51
			}
52
		} elsif(defined($ENV{'AUTHOR_TESTING'})) {
53
			fail('Test failed');
54
			skip('Test failed', 15);
55
		} else {
56
			skip("Couldn't instantiate class", 16);
57
		}
58
	}
59
}