File: author-001_all_locales.t

package info (click to toggle)
libdatetime-format-strptime-perl 1.5600-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 284 kB
  • ctags: 15
  • sloc: perl: 1,453; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,774 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
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

BEGIN {
  unless ($ENV{AUTHOR_TESTING}) {
    require Test::More;
    Test::More::plan(skip_all => 'these tests are for testing by the author');
  }
}

use strict;
use warnings;

use Test::More 0.88;
use DateTime::Format::Strptime;
use DateTime::Locale;
use DateTime;

my @locales = DateTime::Locale->ids;
@locales = sort(@locales);

diag("Checking Day Names");
my $pattern = "%Y-%m-%d %A";
foreach my $locale (@locales) {
    foreach my $day ( 1 .. 7 ) {
        my $dt = DateTime->now( locale => $locale )->set( day => $day );
        my $input = $dt->strftime($pattern);
        my $strptime;
        eval {
            $strptime = DateTime::Format::Strptime->new(
                pattern  => $pattern,
                locale   => $locale,
                on_error => 'croak',
            );
        };
        ok( $@ eq '', "Constructor with Day Name" );

        my $parsed;
        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
        diag("[$@]") if $@ ne '';
        ok( $@ eq '', "Parsed with Day Name" );

        is( $parsed->strftime($pattern), $input, "Matched with Day Name" );
    }
}

diag("Checking Month Names");
$pattern = "%Y-%m-%d %B";
foreach my $locale (@locales) {
    foreach my $month ( 1 .. 12 ) {
        my $dt = DateTime->now( locale => $locale )->truncate( to => 'month' )
            ->set( month => $month );
        my $input = $dt->strftime($pattern);
        my $strptime;
        eval {
            $strptime = DateTime::Format::Strptime->new(
                pattern  => $pattern,
                locale   => $locale,
                on_error => 'croak',
            );
        };
        ok( $@ eq '', "Constructor with Month Name" );

        my $parsed;
        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
        diag("[$@]") if $@ ne '';
        ok( $@ eq '', "Parsed with Month Name" );

        is( $parsed->strftime($pattern), $input, "Matched with Month Name" );
    }
}

diag("Checking AM/PM tokens");
$pattern = "%Y-%m-%d %H:%M %p";
foreach my $locale (@locales) {
    foreach my $hour ( 11, 12 ) {
        my $dt = DateTime->now( locale => $locale )->set( hour => $hour );
        my $input = $dt->strftime($pattern);
        my $strptime;
        eval {
            $strptime = DateTime::Format::Strptime->new(
                pattern  => $pattern,
                locale   => $locale,
                on_error => 'croak',
            );
        };
        ok( $@ eq '', "Constructor with Meridian" );

        my $parsed;
        eval { $parsed = $strptime->parse_datetime($input); } unless $@;
        diag("[$@]") if $@ ne '';
        ok( $@ eq '', "Parsed with Meridian" );

        is( $parsed->strftime($pattern), $input, "Matched with Meridian" );
    }
}


done_testing();