DateTime-Format-Strptime

 view release on metacpan or  search on metacpan

t/errors.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More 0.96;
use Test::Fatal;

use DateTime::Format::Strptime;

subtest(
    'valid constructor',
    sub {
        my $parser;
        is(
            exception {
                $parser = DateTime::Format::Strptime->new( pattern => '%Y' )
            },
            undef,
            'no exception when constructing object with valid pattern'
        );
        isa_ok(
            $parser,
            'DateTime::Format::Strptime',
        );
    }
);

subtest(
    'constructor error',
    sub {
        my $parser;
        like(
            exception {
                $parser
                    = DateTime::Format::Strptime->new( pattern => '%Y %Q' )
            },
            qr/\QPattern contained an unrecognized strptime token, "%Q"/,
            'no exception when constructing object with valid pattern'
        );
        is(
            $parser,
            undef,
            'constructor does not return object on invalid pattern'
        );
    }
);

{
    my @tests = (
        {
            name    => '12-hour time without meridian',
            pattern => '%Y-%m-%d %I:%M',
            input   => '2015-01-02 11:15',
            error   =>
                qr{\QParsed a 12-hour based hour, "11", but the pattern does not include an AM/PM specifier},
        },
        {
            name    => 'uncrecognized time zone abbreviation',
            pattern => '%Y-%m-%d %Z',
            input   => '2015-01-02 FOO',
            error   =>
                qr{\QParsed an unrecognized time zone abbreviation, "FOO"},
        },
        {
            name    => 'ambiguous time zone abbreviation',
            pattern => '%Y-%m-%d %Z',



( run in 1.200 second using v1.01-cache-2.11-cpan-54e63673c56 )