File: 44set-formatter.t

package info (click to toggle)
libdatetime-perl 2%3A1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,504 kB
  • sloc: perl: 2,964; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 707 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
use strict;
use warnings;

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

use DateTime;
use overload;

my $dt = DateTime->now;

like(
    exception { $dt->set_formatter('Invalid::Formatter') },
    qr/\QValidation failed for type named Maybe[Formatter]/,
    'set_format is validated'
);

SKIP:
{
    ## no critic (BuiltinFunctions::ProhibitStringyEval)
    skip 'This test requires DateTime::Format::Strptime 1.2000+', 1
        unless eval 'use DateTime::Format::Strptime 1.2000; 1;';

    my $formatter = DateTime::Format::Strptime->new(
        pattern => '%Y%m%d %T',
    );

    is(
        $dt->set_formatter($formatter),
        $dt,
        'set_formatter returns the datetime object'
    );
}

done_testing();