PageRenderTime 44ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/t/020_constraints/002_japanese.t

http://github.com/tokuhirom/formvalidator-lite
Unknown | 93 lines | 81 code | 12 blank | 0 comment | 0 complexity | 72362c138121135d49552a2241d0389b MD5 | raw file
Possible License(s): AGPL-1.0
 1use strict;
 2use warnings;
 3use utf8;
 4use Test::Base;
 5use FormValidator::Lite qw/Japanese/;
 6use CGI;
 7
 8plan tests => 12;
 9
10filters {
11    query    => [qw/eval/],
12    rule     => [qw/eval/],
13    expected => [qw/eval/],
14};
15
16run {
17    my $block = shift;
18    my $q = CGI->new($block->query);
19
20    my $v = FormValidator::Lite->new($q);
21    $v->check(
22        $block->rule
23    );
24
25    my @expected = $block->expected;
26    while (my ($key, $val) = splice(@expected, 0, 2)) {
27        is($v->is_error($key), $val, $block->name);
28    }
29};
30
31
32__END__
33
34=== HIRAGANA
35--- query: { hoge => '????????', fuga => '????', haga => 'asciii', hoga => '?????  ????'}
36--- rule
37(
38    hoge => [qw/HIRAGANA/],
39    fuga => [qw/HIRAGANA/],
40    hoga => [qw/HIRAGANA/],
41    haga => [qw/HIRAGANA/],
42);
43--- expected
44(
45    hoge => 0,
46    fuga => 1,
47    hoga => 0,
48    haga => 1,
49)
50
51=== KATAKANA
52--- query: { 'p1' => '????????', 'p2' => '????', 'p3' => '???? ? ????', p4 => 'ascii'}
53--- rule
54(
55    p1 => [qw/KATAKANA/],
56    p2 => [qw/KATAKANA/],
57    p3 => [qw/KATAKANA/],
58    p4 => [qw/KATAKANA/],
59);
60--- expected
61(
62    p1 => 1,
63    p2 => 0,
64    p3 => 0,
65    p4 => 1,
66)
67
68=== JTEL
69--- query: { 'p1' => '666-666-6666', 'p2' => '03-5555-5555'}
70--- rule
71(
72    p1 => [qw/JTEL/],
73    p2 => [qw/JTEL/],
74);
75--- expected
76(
77    p1 => 1,
78    p2 => 0,
79)
80
81=== JZIP
82--- query: { 'p1' => '155-0044', 'p2' => '03-5555-5555'}
83--- rule
84(
85    p1 => [qw/JZIP/],
86    p2 => [qw/JZIP/],
87);
88--- expected
89(
90    p1 => 0,
91    p2 => 1,
92)
93