File: nanp.t

package info (click to toggle)
libnumber-phone-perl 3.6006-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 136,072 kB
  • sloc: perl: 2,719; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,871 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

use strict;

use lib 't/inc';
use fatalwarnings;

our $CLASS = 'Number::Phone';
eval "use $CLASS";
use Test::More;
use Scalar::Util qw(blessed);

END { done_testing(); }

require 'common-nanp_and_libphonenumber_tests.pl';

regulators();

sub regulators {
    note("NANP regulators");
    my %test_numbers = (
        NANP => '866 623 2282',
        CA   => '613 563 7242',
        US   => '202 418 1440',
        AG   => '268 480 4000',
        AI   => '264 497 3924',
        AS   => '684 633 0001',
        BB   => '246 434 3444',
        BM   => '441 292 4595',
        BS   => '242 302 7000',
        DM   => '767 448 1408',
        DO   => '809 547 1000',
        GD   => '473 435 6872',
        GU   => '671 632 3365',
        JM   => '876 511 5013',
        KN   => '869 465 1000',
        KY   => '345 945 8284',
        LC   => '758 453 9300',
        MP   => '670 682 4555',
        MS   => '664 491 2230',
        PR   => '787 729 3131',
        SX   => '721 555 0001',
        TC   => '649 946 5231',
        TT   => '868 624 6982',
        VC   => '784 488 1000',
        VG   => '284 494 4444',
        VI   => '340 712 9960'
    );
    
    my %regulators = (
        NANP => 'NANPA',
        CA   => 'CRTC',
        US   => 'FCC',
        AG   => '',
        AI   => 'PUC',
        AS   => 'ASTCA',
        BB   => 'FTC',
        BM   => 'Ministry of Telecommunications and E-Commerce',
        BS   => 'PUC',
        DM   => 'ECTEL',
        DO   => 'Indotel',
        GD   => 'NTRC',
        GU   => 'GTA',
        JM   => 'OUR',
        KN   => 'ECTEL',
        KY   => 'ICTA',
        LC   => 'ECTEL',
        MP   => '',
        MS   => '',
        PR   => '',
        SX   => '',
        TC   => '',
        TT   => 'RIC',
        VC   => 'NTRC',
        VG   => 'Ministry of Communications and Works',
        VI   => ''
    );
    
    foreach my $country (sort keys %test_numbers) {
        my $targetclass = ($country eq 'NANP') ?
            'Number::Phone::NANP' :
            'Number::Phone::NANP::'.$country;
        my $number = Number::Phone->new('+1'.$test_numbers{$country});
        is(blessed($number), $targetclass,         "create $targetclass");
    
        ok(!defined($number->country()), "NANP has no country() info")
            if($country eq 'NANP');
        is($number->country(), $country, "$country has right country() info")
            if($country ne 'NANP');
        ok(!defined($number->regulator()), "$country has no regulator info")
            if($regulators{$country} eq '');
        like($number->regulator(), qr/^$regulators{$country}/, "$country has right regulator() info")
            if($regulators{$country} ne '');
        is($number->country_code(), 1, "$country has country code 1");
        like($number->format(), qr/\+1 \d{3} \d{3} \d{4}$/, "$country can format numbers");
    }
}