File: import.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 (39 lines) | stat: -rw-r--r-- 912 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
use strict;
use warnings;

use Test::More;

{
    eval q[
    package SampleClass1;
    use DateTime::Format::Builder
        parsers => {
        parse_datetime => [
        {
            regex => qr/^(\d{4})(\d\d)(d\d)(\d\d)(\d\d)(\d\d)$/,
            params => [qw( year month day hour minute second )],
        },
        {
            regex => qr/^(\d{4})(\d\d)(\d\d)$/,
            params => [qw( year month day )],
        },
        ],
        };
    ];
    ok( !$@, "No errors when creating the class." );

    my $parser = SampleClass1->new();
    isa_ok( $parser => 'SampleClass1' );

    my $dt = eval { $parser->parse_datetime("20040506") };
    isa_ok( $dt => 'DateTime' );

    is( $dt->year  => 2004, 'Year is 2004' );
    is( $dt->month => 5,    'Year is 2004' );
    is( $dt->day   => 6,    'Year is 2004' );

    eval { $parser->fnerk };
    ok( $@, "There is no fnerk." );
}

done_testing();