1
2BEGIN {
3  unless ($ENV{AUTHOR_TESTING}) {
4    require Test::More;
5    Test::More::plan(skip_all => 'these tests are for testing by the author');
6  }
7}
8
9use strict;
10use warnings;
11
12use Test::More 0.88;
13use DateTime::Format::Strptime;
14use DateTime::Locale;
15use DateTime;
16
17my @locales = DateTime::Locale->ids;
18@locales = sort(@locales);
19
20diag("Checking Day Names");
21my $pattern = "%Y-%m-%d %A";
22foreach my $locale (@locales) {
23    foreach my $day ( 1 .. 7 ) {
24        my $dt = DateTime->now( locale => $locale )->set( day => $day );
25        my $input = $dt->strftime($pattern);
26        my $strptime;
27        eval {
28            $strptime = DateTime::Format::Strptime->new(
29                pattern  => $pattern,
30                locale   => $locale,
31                on_error => 'croak',
32            );
33        };
34        ok( $@ eq '', "Constructor with Day Name" );
35
36        my $parsed;
37        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
38        diag("[$@]") if $@ ne '';
39        ok( $@ eq '', "Parsed with Day Name" );
40
41        is( $parsed->strftime($pattern), $input, "Matched with Day Name" );
42    }
43}
44
45diag("Checking Month Names");
46$pattern = "%Y-%m-%d %B";
47foreach my $locale (@locales) {
48    foreach my $month ( 1 .. 12 ) {
49        my $dt = DateTime->now( locale => $locale )->truncate( to => 'month' )
50            ->set( month => $month );
51        my $input = $dt->strftime($pattern);
52        my $strptime;
53        eval {
54            $strptime = DateTime::Format::Strptime->new(
55                pattern  => $pattern,
56                locale   => $locale,
57                on_error => 'croak',
58            );
59        };
60        ok( $@ eq '', "Constructor with Month Name" );
61
62        my $parsed;
63        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
64        diag("[$@]") if $@ ne '';
65        ok( $@ eq '', "Parsed with Month Name" );
66
67        is( $parsed->strftime($pattern), $input, "Matched with Month Name" );
68    }
69}
70
71diag("Checking AM/PM tokens");
72$pattern = "%Y-%m-%d %H:%M %p";
73foreach my $locale (@locales) {
74    foreach my $hour ( 11, 12 ) {
75        my $dt = DateTime->now( locale => $locale )->set( hour => $hour );
76        my $input = $dt->strftime($pattern);
77        my $strptime;
78        eval {
79            $strptime = DateTime::Format::Strptime->new(
80                pattern  => $pattern,
81                locale   => $locale,
82                on_error => 'croak',
83            );
84        };
85        ok( $@ eq '', "Constructor with Meridian" );
86
87        my $parsed;
88        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
89        diag("[$@]") if $@ ne '';
90        ok( $@ eq '', "Parsed with Meridian" );
91
92        is( $parsed->strftime($pattern), $input, "Matched with Meridian" );
93    }
94}
95
96
97done_testing();
98