File: 112_australia.t

package info (click to toggle)
libregexp-common-perl 2017060201-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: perl: 17,868; makefile: 2
file content (104 lines) | stat: -rwxr-xr-x 3,414 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
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
#!/usr/bin/perl

use strict;
use warnings;
no  warnings 'syntax';

use Regexp::Common;
use Test::More;

my $r = eval "require Test::Regexp; 1";

unless ($r) {
    print "1..0 # SKIP Test::Regexp not found\n";
    exit;
}

my $Test = Test::Regexp:: -> new -> init (
    pattern       =>  $RE {zip} {Australia},
    keep_pattern  =>  $RE {zip} {Australia} {-keep},
    name          => "Australian zip codes",
);

my $Test_none = Test::Regexp:: -> new -> init (
    pattern       =>  $RE {zip} {Australia} {-prefix => 'no'},
    keep_pattern  =>  $RE {zip} {Australia} {-prefix => 'no'} {-keep},
    name          => "Australian zip codes (no prefix allowed)",
);

my $Test_iso = Test::Regexp:: -> new -> init (
    pattern       =>  $RE {zip} {Australia} {-prefix  => 'yes'}
                                            {-country => 'iso'},
    keep_pattern  =>  $RE {zip} {Australia} {-prefix  => 'yes'}
                                            {-country => 'iso'} {-keep},
    name          => "Australian zip codes (ISO prefix required)",
);

my $Test_cept = Test::Regexp:: -> new -> init (
    pattern       =>  $RE {zip} {Australia} {-prefix  => 'yes'}
                                            {-country => 'cept'},
    keep_pattern  =>  $RE {zip} {Australia} {-prefix  => 'yes'}
                                            {-country => 'cept'} {-keep},
    name          => "Australian zip codes (CEPT prefix required)",
);

my @valid = ("0909", 1445, 3500, 9726);   # Some selection.

my $ISO  = "AU";
my $CEPT = "AUS";

foreach my $zip (@valid) {
    #
    # No prefix
    #
    $Test      ->    match ($zip,
                           [$zip, undef, $zip],
                           test => "No prefix");
    $Test_none ->    match ($zip,
                           [$zip, undef, $zip],
                           test => "No prefix");
    $Test_iso  -> no_match ($zip, reason => "No prefix present");
    $Test_cept -> no_match ($zip, reason => "No prefix present");

    #
    # Can we prefix the zip code?
    #
    my $zip_iso  = "$ISO-$zip";
    my $zip_cept = "$CEPT-$zip";

    # 
    # ISO prefix
    #
    $Test      ->    match ($zip_iso,
                           [$zip_iso, $ISO, $zip],
                           test => "Use ISO prefix");
    $Test_none -> no_match ($zip_iso, reason => "Prefix used");
    $Test_iso  ->    match ($zip_iso,
                           [$zip_iso, $ISO, $zip],
                           test => "Use ISO prefix");
    $Test_cept -> no_match ($zip_iso, reason => "ISO prefix used");

    # 
    # CEPT prefix
    #
    $Test      ->    match ($zip_cept,
                           [$zip_cept, $CEPT, $zip],
                           test => "Use CEPT prefix");
    $Test_none -> no_match ($zip_cept, reason => "Prefix used");
    $Test_iso  -> no_match ($zip_cept, reason => "CEPT prefix used");
    $Test_cept ->    match ($zip_cept,
                           [$zip_cept, $CEPT, $zip],
                           test => "Use CEPT prefix");

    #
    # An illegal prefix should never match
    #
    my $zip_illegal = "DE-$zip";
    $Test      -> no_match ($zip_illegal, reason => "Illegal prefix used");
    $Test_none -> no_match ($zip_illegal, reason => "Illegal prefix used");
    $Test_iso  -> no_match ($zip_illegal, reason => "Illegal prefix used");
    $Test_cept -> no_match ($zip_illegal, reason => "Illegal prefix used");
}


done_testing;