File: on_fail_sub.t

package info (click to toggle)
libdatetime-format-builder-perl 0.8300-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 504 kB
  • sloc: perl: 1,236; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,121 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
use strict;
use warnings;

use Test::More;

use DateTime::Format::Builder;

{
    eval q|
        package DTFB::Sub;
        use base qw( DateTime::Format::Builder );

        sub on_fail {
            return undef;
        }

        1;

        package DTFB::OnFailSubTest;

        BEGIN {
            DTFB::Sub->import(
                parsers => {
                    parse_datetime => [
                    {strptime=> '%m/%d/%Y'},
                    {strptime=> '%Y/%m/%d'},
                    ]
                }
            );
        }

        1;
    |;
    ok( !$@, "Made class" );
    diag $@ if $@;

    my $o          = DTFB::OnFailSubTest->new;
    my $good_parse = $o->parse_datetime("2003/08/09");
    isa_ok( $good_parse, 'DateTime' );
    is( $good_parse->year  => 2003, "Year good" );
    is( $good_parse->month => 8,    "Month good" );
    is( $good_parse->day   => 9,    "Day good" );

    my $bad_parse = eval { $o->parse_datetime("Fnerk") };
    ok( !$@, "Bad parse gives no error" );
    diag $@ if $@;
    ok( ( !defined($bad_parse) ), "Bad parse correctly gives undef" );
}

done_testing();