1use strict;
2use warnings;
3
4use Test2::V0;
5use Test::File::ShareDir::Dist { 'DateTime-Locale' => 'share' };
6
7use DateTime::Locale;
8
9## no critic (Modules::ProhibitMultiplePackages)
10
11{
12    package DateTime::Locale::en_GB_RIDAS;
13
14    use base qw(DateTime::Locale::Base);
15}
16
17{
18    package DateTime::Locale::en_FOO_BAR;
19
20    use base qw(DateTime::Locale::Base);
21}
22
23{
24    package DateTime::Locale::en_BAZ_BUZ;
25
26    use base qw(DateTime::Locale::Base);
27}
28
29{
30    package DateTime::Locale::en_QUUX_QUAX;
31
32    use base qw(DateTime::Locale::Base);
33}
34
35{
36    package DateTime::Locale::fr_FR_BZH2;
37    @DateTime::Locale::fr_FR_BZH2::ISA = qw(DateTime::Locale::Base);
38    sub short_date_format {'test test2'}
39}
40
41{
42    package Other::Locale::fr_FR_BZH;
43    @Other::Locale::fr_FR_BZH::ISA = qw(DateTime::Locale::Base);
44    sub short_date_format {'test test2'}
45}
46
47like(
48    dies { DateTime::Locale->register( id => '@' ) },
49    qr/\Q'\@' or '=' are not allowed in locale ids\E/,
50    'locale id test with @'
51);
52
53like(
54    dies { DateTime::Locale->register( id => '=' ) },
55    qr/\Q'\@' or '=' are not allowed in locale ids\E/,
56    'locale id test with ='
57);
58
59DateTime::Locale->register(
60    id           => 'en_GB_RIDAS',
61    en_language  => 'English',
62    en_territory => 'United Kingdom',
63    en_variant   => 'Ridas Custom Locale',
64);
65
66{
67    my $l = DateTime::Locale->load('en_GB_RIDAS');
68    isa_ok( $l, 'DateTime::Locale::en_GB_RIDAS' );
69    ok( $l, 'was able to load en_GB_RIDAS' );
70    is( $l->variant, 'Ridas Custom Locale', 'variant is set properly' );
71}
72
73DateTime::Locale->register(
74    {
75        id           => 'en_FOO_BAR',
76        en_language  => 'English',
77        en_territory => 'United Kingdom',
78        en_variant   => 'Foo Bar',
79    }, {
80        id           => 'en_BAZ_BUZ',
81        en_language  => 'English',
82        en_territory => 'United Kingdom',
83        en_variant   => 'Baz Buz',
84    },
85);
86
87{
88    my $l = DateTime::Locale->load('en_FOO_BAR');
89    isa_ok( $l, 'DateTime::Locale::en_FOO_BAR' );
90    ok( $l, 'was able to load en_FOO_BAR' );
91    is( $l->variant, 'Foo Bar', 'variant is set properly' );
92
93    $l = DateTime::Locale->load('en_BAZ_BUZ');
94    isa_ok( $l, 'DateTime::Locale::en_BAZ_BUZ' );
95    ok( $l, 'was able to load en_BAZ_BUZ' );
96    is( $l->variant, 'Baz Buz', 'variant is set properly' );
97}
98
99# backwards compatibility
100DateTime::Locale->register(
101    {
102        id           => 'en_QUUX_QUAX',
103        en_language  => 'English',
104        en_territory => 'United Kingdom',
105        en_variant   => 'Wacko',
106    },
107);
108
109{
110    my $l = DateTime::Locale->load('en_QUUX_QUAX');
111    isa_ok( $l, 'DateTime::Locale::en_QUUX_QUAX' );
112    ok( $l, 'was able to load en_QUUX_QUAX' );
113    is( $l->variant, 'Wacko', 'variant is set properly' );
114}
115
116# there was a bug with register if the class passed in had an explicit
117# DateTime:: namespace
118{
119    DateTime::Locale->register(
120        id           => 'fr_FR_BZH2',
121        en_language  => 'French2',
122        en_territory => 'French2',
123        en_variant   => 'Britanny2',
124        class        => 'DateTime::Locale::fr_FR_BZH2',
125    );
126
127    my $l = DateTime::Locale->load('fr_FR_BZH2');
128    isa_ok( $l, 'DateTime::Locale::fr_FR_BZH2' );
129    ok( $l, 'was able to load fr_FR_BZH2' );
130    is( $l->short_date_format, 'test test2',   'short date' );
131    is( $l->name, 'French2 French2 Britanny2', 'name is also set' );
132}
133
134# with a custom namespace
135{
136    DateTime::Locale->register(
137        id           => 'fr_FR_BZH',
138        en_language  => 'French',
139        en_territory => 'French',
140        en_variant   => 'Britanny',
141        class        => 'Other::Locale::fr_FR_BZH',
142    );
143
144    my $l = DateTime::Locale->load('fr_FR_BZH');
145    isa_ok( $l, 'Other::Locale::fr_FR_BZH' );
146    ok( $l, 'was able to load fr_FR_BZH' );
147    is( $l->short_date_format, 'test test2',             'short date' );
148    is( $l->name,              'French French Britanny', 'name is also set' );
149}
150
151done_testing();
152