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
|
#!perl -T
use strict;
use warnings;
use Test::More tests => 35;
use Date::Extract;
my $parser = Date::Extract->new();
ok($parser, "got a parser out of Date::Extract->new");
ok($parser->isa("Date::Extract"), "new parser is a Date::Extract object");
# returns {{{
for my $opt (qw/first last earliest latest all all_cron/) {
$parser = Date::Extract->new(returns => $opt);
ok($parser, "got a parser out of Date::Extract->new(returns => '$opt')");
ok($parser->isa("Date::Extract"), "new parser is a Date::Extract object");
}
$parser = eval { Date::Extract->new(returns => "invalid argument") };
ok(!$parser, "did NOT get a parser out of Date::Extract->new(returns => 'invalid argument')");
like($@, qr/Invalid `returns` passed to constructor/, "(returns => 'invalid argument') gave a sensible error message");
like($@, qr/01-new\.t/, "invalid `returns` error reported from caller's perspective");
# }}}
# prefer nearest, prefer future, prefer past {{{
for my $opt (qw/nearest future past/) {
$parser = Date::Extract->new(prefer => $opt);
ok($parser, "got a parser out of Date::Extract->new(prefers => '$opt')");
ok($parser->isa("Date::Extract"), "new parser is a Date::Extract object");
}
$parser = eval { Date::Extract->new(prefers => "invalid argument") };
ok(!$parser, "did NOT get a parser out of Date::Extract->new(prefers => 'invalid argument')");
like($@, qr/Invalid `prefers` passed to constructor/, "(prefers => 'invalid argument') gave a sensible error message");
like($@, qr/01-new\.t/, "invalid `prefers` error reported from caller's perspective");
# }}}
# format {{{
$parser = eval { Date::Extract->new(format => "invalid argument") };
ok(!$parser, "did NOT get a parser out of Date::Extract->new(format => 'invalid argument')");
like($@, qr/Invalid `format` passed to constructor/, "(format => 'invalid argument') gave a sensible error message");
like($@, qr/01-new\.t/, "invalid `format` error reported from caller's perspective");
for my $opt (qw/DateTime verbatim epoch/) {
$parser = Date::Extract->new(format => $opt);
ok($parser, "got a parser out of Date::Extract->new(format => '$opt')");
ok($parser->isa("Date::Extract"), "new parser is a Date::Extract object");
}
# }}}
|