summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2018-05-11 19:24:30 +0200
committerYorhel <git@yorhel.nl>2018-05-11 19:24:30 +0200
commitcc26eedd495cd230e2cc45423f9d98000adde6d8 (patch)
tree86577cac0ebd9232ab44175db65f9de460409af6 /t
parent6b3e403004b30d77b3011a6c65f0ad4f870cd622 (diff)
TUWF::Validate: Add enum validation
Diffstat (limited to 't')
-rw-r--r--t/validate.t7
1 files changed, 7 insertions, 0 deletions
diff --git a/t/validate.t b/t/validate.t
index ffecb7b..82f979d 100644
--- a/t/validate.t
+++ b/t/validate.t
@@ -116,6 +116,13 @@ t { type => 'hash', length => 1, unknown => 'accept' }, {qw/1 a 2 b/}, {qw/1 a 2
t { type => 'hash', length => 1, keys => {a => {required=>0}, b => {required=>0}} }, {a=>1}, {a=>1}, undef;
t { regex => '^a' }, 'abc', 'abc', undef; # XXX: Can't use qr// here because t() does dclone(). The 'hex' test covers that case anyway.
t { regex => '^a' }, 'cba', 'cba', { validation => 'regex', regex => '^a', got => 'cba' };
+t { enum => [1,2] }, 1, 1, undef;
+t { enum => [1,2] }, 2, 2, undef;
+t { enum => [1,2] }, 3, 3, { validation => 'enum', expected => [1,2], got => 3 };
+t { enum => 1 }, 1, 1, undef;
+t { enum => 1 }, 2, 2, { validation => 'enum', expected => [1], got => 2 };
+t { enum => {a=>1,b=>2} }, 'a', 'a', undef;
+t { enum => {a=>1,b=>2} }, 'c', 'c', { validation => 'enum', expected => ['a','b'], got => 'c' };
t { anybool => 1 }, 1, 1, undef;
t { anybool => 1 }, undef, 0, undef;
t { anybool => 1 }, '', 0, undef;