PageRenderTime 32ms CodeModel.GetById 24ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/t/020_constraints/008_time.t

http://github.com/tokuhirom/formvalidator-lite
Unknown | 101 lines | 86 code | 15 blank | 0 comment | 0 complexity | 0823369a98d42cedca76b66528c9e833 MD5 | raw file
Possible License(s): AGPL-1.0
  1use strict;
  2use warnings;
  3use utf8;
  4use Test::Base;
  5use FormValidator::Lite;
  6use CGI;
  7
  8FormValidator::Lite->load_constraints(qw/Time/);
  9
 10plan tests => 1*blocks;
 11
 12filters {
 13    query    => [qw/eval/],
 14    rule     => [qw/eval/],
 15    expected => [qw/eval/],
 16};
 17
 18run {
 19    my $block = shift;
 20    my $q = CGI->new($block->query);
 21
 22    my $v = FormValidator::Lite->new($q);
 23    $v->check(
 24        $block->rule
 25    );
 26
 27    my @expected = $block->expected;
 28    while (my ($key, $val) = splice(@expected, 0, 2)) {
 29        is($v->is_error($key), $val, $block->name);
 30    }
 31};
 32
 33
 34__END__
 35
 36=== TIME should success
 37--- query: { h => 12, m => 0, s => 30 }
 38--- rule
 39(
 40    {date => [qw/h m s/]} => ['TIME'],
 41)
 42--- expected
 43(
 44    date => 0,
 45)
 46 
 47=== TIME should fail
 48--- query: { h => 24, m => 0, s => 0 }
 49--- rule
 50(
 51    {date => [qw/h m s/]} => ['TIME'],
 52)
 53--- expected
 54(
 55    date => 1,
 56)
 57
 58=== TIME-NOT_NULL
 59--- query: {  }
 60--- rule
 61(
 62    {date => [qw/h m s/]} => ['TIME', 'NOT_NULL'],
 63)
 64--- expected
 65(
 66    date => 1,
 67)
 68
 69=== TIME-NOT_NULL
 70--- query: {  }
 71--- rule
 72(
 73    {date => [qw/h m s/]} => ['NOT_NULL'],
 74)
 75--- expected
 76(
 77    date => 1,
 78)
 79
 80=== TIME
 81--- query: { time => '12:30:00' }
 82--- rule
 83(
 84    date => ['TIME'],
 85)
 86--- expected
 87(
 88    date => 0,
 89)
 90
 91=== TIME should not warn with ''
 92--- query: { h => '', m => '', s => ''}
 93--- rule
 94(
 95    {date => [qw/h m s/]} => ['TIME'],
 96)
 97--- expected
 98(
 99    date => 1,
100)
101