File: weird_little_islands.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 (59 lines) | stat: -rw-r--r-- 2,139 bytes parent folder | download
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
#!/usr/bin/perl -w

use strict;

use lib 't/inc';
use fatalwarnings;

use Number::Phone::UK;
use Test::More;

END { done_testing(); }

my $data = {
  JE => {
    mobile     => '+44 7700 300000', # used specifically because there's a special case for 7700 900
    geographic => '+44 1534 440000',
    operator   => qr/^(JT|Sure) \(Jersey\) Limited$/,
    regulator  => 'Office of Utility Regulation, http://www.cicra.gg'
  },
  GG => {
    mobile     => '+44 7781 000000',
    geographic => '+44 1481 200000',
    operator   => 'Sure (Guernsey) Limited',
    regulator  => 'Office of Utility Regulation, http://www.cicra.gg'
  },
  IM => {
    mobile      => ['+44 7624 000000', '+44 7457 600000'],
    geographic  => '+44 1624 500000',
    specialrate => '+44 8456247890',
    operator    => qr/^(Manx Telecom Trading Limited|Sure \(Isle of Man\) Limited)$/,
    regulator   => 'Isle of Man Communications Commission, http://www.gov.im/government/boards/telecommunications.xml'
  },
};

foreach my $cc (keys %{$data}) {
  my $data = $data->{$cc};
  foreach my $type (qw(mobile geographic specialrate)) {
      next unless(exists($data->{$type}));

      my $method = "is_$type";
      foreach my $number (ref($data->{$type}) ? @{$data->{$type}} : $data->{$type}) {
          my $object = Number::Phone->new($number);
          isa_ok($object, "Number::Phone::UK::$cc", "isa N::P::UK::$cc");
          isa_ok($object, 'Number::Phone::UK', "isa N::P::UK by inheritance");
          is($object->country(), $cc, "country() method works");
          ok($object->$method(), $number." detected as being $type");
          is($object->format(), $number, "format() method works");
          is_deeply(
              [sort $object->type()],
              [sort ($method, qw(is_allocated is_valid))],
              "type() works"
          );
          ref($data->{operator})
              ? like($object->operator(), $data->{operator}, "inherited operator() works")
              :   is($object->operator(), $data->{operator}, "inherited operator() works");
          is($object->regulator(), $data->{regulator}, "regulator() works");
      }
  }
}