Skip to content

Commit

Permalink
Added more tests, labels and cleaned the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbn committed Feb 2, 2021
1 parent 3c26e90 commit a45f784
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions t/validator_matches_date_format.t
Expand Up @@ -5,32 +5,44 @@ use lib qw(../lib lib ../t t);
use TestUtil;
use Test::Exception;
use DateTime;
use Test::More tests => 6;
use Test::More;

require_ok( 'Workflow::Validator::MatchesDateFormat' );
require_ok( 'Workflow::Validator::MatchesDateFormat');

my $validator;
my $wf;

dies_ok { $validator = Workflow::Validator::MatchesDateFormat->new({}) };
dies_ok { $validator = Workflow::Validator::MatchesDateFormat->new({}) } 'Constructor without parameters, we die';

dies_ok { $validator = Workflow::Validator::MatchesDateFormat->new({ date_format => bless {} }) } 'Constructor with bad parameters, we die';

ok($validator = Workflow::Validator::MatchesDateFormat->new({
date_format => '%Y-%m-%d',
}));
}), 'Constructor with date_format provided, should succeed');

isa_ok($validator, 'Workflow::Validator');

ok($validator->validate($wf, '2005-05-13'));
ok($validator->validate($wf, '2005-05-13'), 'validating a legal date');

lives_ok { $validator->validate($wf) } 'Validation without parameters, we live';

dies_ok { $validator->validate($wf, bless {}) } 'Validation with bad object, we die';

my $dt = DateTime->new(
year => 1964,
month => 10,
day => 16,
hour => 16,
minute => 12,
second => 47,
nanosecond => 500000000,
time_zone => 'Asia/Taipei',
);

my $dt = DateTime->new( year => 1964,
month => 10,
day => 16,
hour => 16,
minute => 12,
second => 47,
nanosecond => 500000000,
time_zone => 'Asia/Taipei',
);
lives_ok { $validator->validate($wf, $dt) } 'Validation of DateTime parameter, we live';

lives_ok { $validator->validate($wf, $dt) };
throws_ok( sub { $validator->validate($wf, '13-05-2005'); }, qr/Date '13-05-2005' does not match required pattern '%Y-%m-%d'/,
'Exception, validation with non-conformant date parameter',
);

done_testing();

0 comments on commit a45f784

Please sign in to comment.