File: register.t

package info (click to toggle)
libdatetime-locale-perl 1%3A1.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,688 kB
  • sloc: perl: 295,819; sh: 23; makefile: 2
file content (151 lines) | stat: -rw-r--r-- 3,938 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use strict;
use warnings;

use Test2::V0;
use Test::File::ShareDir::Dist { 'DateTime-Locale' => 'share' };

use DateTime::Locale;

## no critic (Modules::ProhibitMultiplePackages)

{
    package DateTime::Locale::en_GB_RIDAS;

    use base qw(DateTime::Locale::Base);
}

{
    package DateTime::Locale::en_FOO_BAR;

    use base qw(DateTime::Locale::Base);
}

{
    package DateTime::Locale::en_BAZ_BUZ;

    use base qw(DateTime::Locale::Base);
}

{
    package DateTime::Locale::en_QUUX_QUAX;

    use base qw(DateTime::Locale::Base);
}

{
    package DateTime::Locale::fr_FR_BZH2;
    @DateTime::Locale::fr_FR_BZH2::ISA = qw(DateTime::Locale::Base);
    sub short_date_format {'test test2'}
}

{
    package Other::Locale::fr_FR_BZH;
    @Other::Locale::fr_FR_BZH::ISA = qw(DateTime::Locale::Base);
    sub short_date_format {'test test2'}
}

like(
    dies { DateTime::Locale->register( id => '@' ) },
    qr/\Q'\@' or '=' are not allowed in locale ids\E/,
    'locale id test with @'
);

like(
    dies { DateTime::Locale->register( id => '=' ) },
    qr/\Q'\@' or '=' are not allowed in locale ids\E/,
    'locale id test with ='
);

DateTime::Locale->register(
    id           => 'en_GB_RIDAS',
    en_language  => 'English',
    en_territory => 'United Kingdom',
    en_variant   => 'Ridas Custom Locale',
);

{
    my $l = DateTime::Locale->load('en_GB_RIDAS');
    isa_ok( $l, 'DateTime::Locale::en_GB_RIDAS' );
    ok( $l, 'was able to load en_GB_RIDAS' );
    is( $l->variant, 'Ridas Custom Locale', 'variant is set properly' );
}

DateTime::Locale->register(
    {
        id           => 'en_FOO_BAR',
        en_language  => 'English',
        en_territory => 'United Kingdom',
        en_variant   => 'Foo Bar',
    }, {
        id           => 'en_BAZ_BUZ',
        en_language  => 'English',
        en_territory => 'United Kingdom',
        en_variant   => 'Baz Buz',
    },
);

{
    my $l = DateTime::Locale->load('en_FOO_BAR');
    isa_ok( $l, 'DateTime::Locale::en_FOO_BAR' );
    ok( $l, 'was able to load en_FOO_BAR' );
    is( $l->variant, 'Foo Bar', 'variant is set properly' );

    $l = DateTime::Locale->load('en_BAZ_BUZ');
    isa_ok( $l, 'DateTime::Locale::en_BAZ_BUZ' );
    ok( $l, 'was able to load en_BAZ_BUZ' );
    is( $l->variant, 'Baz Buz', 'variant is set properly' );
}

# backwards compatibility
DateTime::Locale->register(
    {
        id           => 'en_QUUX_QUAX',
        en_language  => 'English',
        en_territory => 'United Kingdom',
        en_variant   => 'Wacko',
    },
);

{
    my $l = DateTime::Locale->load('en_QUUX_QUAX');
    isa_ok( $l, 'DateTime::Locale::en_QUUX_QUAX' );
    ok( $l, 'was able to load en_QUUX_QUAX' );
    is( $l->variant, 'Wacko', 'variant is set properly' );
}

# there was a bug with register if the class passed in had an explicit
# DateTime:: namespace
{
    DateTime::Locale->register(
        id           => 'fr_FR_BZH2',
        en_language  => 'French2',
        en_territory => 'French2',
        en_variant   => 'Britanny2',
        class        => 'DateTime::Locale::fr_FR_BZH2',
    );

    my $l = DateTime::Locale->load('fr_FR_BZH2');
    isa_ok( $l, 'DateTime::Locale::fr_FR_BZH2' );
    ok( $l, 'was able to load fr_FR_BZH2' );
    is( $l->short_date_format, 'test test2',   'short date' );
    is( $l->name, 'French2 French2 Britanny2', 'name is also set' );
}

# with a custom namespace
{
    DateTime::Locale->register(
        id           => 'fr_FR_BZH',
        en_language  => 'French',
        en_territory => 'French',
        en_variant   => 'Britanny',
        class        => 'Other::Locale::fr_FR_BZH',
    );

    my $l = DateTime::Locale->load('fr_FR_BZH');
    isa_ok( $l, 'Other::Locale::fr_FR_BZH' );
    ok( $l, 'was able to load fr_FR_BZH' );
    is( $l->short_date_format, 'test test2',             'short date' );
    is( $l->name,              'French French Britanny', 'name is also set' );
}

done_testing();