From a45f784eb29805ff03b7277ee2eb603c0d71981f Mon Sep 17 00:00:00 2001 From: jonasbn Date: Tue, 2 Feb 2021 21:29:24 +0100 Subject: [PATCH] Added more tests, labels and cleaned the code a bit --- t/validator_matches_date_format.t | 42 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/t/validator_matches_date_format.t b/t/validator_matches_date_format.t index 9c912fe0..4cc9acce 100644 --- a/t/validator_matches_date_format.t +++ b/t/validator_matches_date_format.t @@ -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();