-
Notifications
You must be signed in to change notification settings - Fork 3
/
06-extra-validator-with-doco.t
49 lines (40 loc) · 1.66 KB
/
06-extra-validator-with-doco.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;
use lib 't/lib';
use Params::Validate::Dependencies qw(:all);
use Params::Validate::Dependencies::two_of;
use Test::More;
use Test::Exception;
END { done_testing(); }
my @pvd = two_of(qw(alpha beta gamma));
ok(foo(alpha => 1, beta => 1) eq 'woot', "correct params, no code-refs");
ok(foo(gamma => 1, beta => 1) eq 'woot', "correct params, no code-refs");
dies_ok(sub { foo(alpha => 1) }, "incorrect params, not enough");
dies_ok(sub { foo(alpha => 1, beta => 1, gamma => 1) }, "incorrect params, too many");
@pvd = two_of('alpha', one_of(qw(beta gamma)));
ok(foo(alpha => 1, beta => 1) eq 'woot', "correct params, code-ref");
ok(foo(alpha => 1, gamma => 1) eq 'woot', "correct params, code-ref");
dies_ok(sub { foo(gamma => 1, beta => 1) }, "incorrect params, fails scalar");
dies_ok(sub { foo(alpha => 1) }, "incorrect params, not enough");
dies_ok(sub { foo(alpha => 1, beta => 1, gamma => 1) }, "incorrect params, fails code-ref");
is(
Params::Validate::Dependencies::document(@pvd),
"two of ('alpha' or one of ('beta' or 'gamma'))",
'auto-doc does tree jibber-jabber'
);
is(
Params::Validate::Dependencies::document(one_of('foo', two_of(qw(bar baz barf)))),
"one of ('foo' or two of ('bar', 'baz' or 'barf'))",
"auto-doc does tree jibber-jabber t'other way round too"
);
SKIP: {
skip "only on perl 5.18 and higher" if($] <= 5.018);
eval 'use Data::Domain::Dependencies qw(Dependencies)';
my $domain = Dependencies(@pvd);
ok(!$domain->inspect({alpha => 1, gamma => 1}), "DDD: correct params");
ok($domain->inspect({alpha => 1, beta => 1, gamma => 1}), "DDD: incorrect params");
}
sub foo {
validate(@_, @pvd);
return 'woot';
}