Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jjatria/validate-with
Add support for validate_with [PRC]
- Loading branch information
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Params::Validate::Dependencies qw( validate_with all_of one_of ); | ||
|
||
use Test::More; | ||
use Test::Exception; | ||
END { done_testing(); } | ||
|
||
sub doc { Params::Validate::Dependencies::document(@_) } | ||
|
||
my $spec = { foo => 1, bar => 1, optional => 0 }; | ||
|
||
# Vanilla call | ||
is_deeply +{ | ||
validate_with( | ||
params => [ foo => 'foo', bar => 'bar', extra => 'extra' ], | ||
spec => $spec, | ||
allow_extra => 1, | ||
), | ||
}, | ||
{ foo => 'foo', bar => 'bar', extra => 'extra' }, | ||
'Vanilla call'; | ||
|
||
dies_ok {; | ||
validate_with( | ||
params => [ foo => 'foo', bar => 'bar' ], | ||
spec => $spec, | ||
dependencies => all_of(qw( foo optional )), | ||
) | ||
} | ||
'Dies if dependency is not met'; | ||
|
||
is_deeply +{ | ||
validate_with( | ||
params => [ foo => 'foo', bar => 'bar' ], | ||
spec => $spec, | ||
dependencies => [ one_of('foo'), one_of('bar') ], | ||
) | ||
}, | ||
{ foo => 'foo', bar => 'bar' }, | ||
'Supports multiple dependencies'; | ||
|
||
is_deeply +{ | ||
validate_with( | ||
params => [ foo => 'foo', bar => 'bar' ], | ||
spec => $spec, | ||
) | ||
}, | ||
{ foo => 'foo', bar => 'bar' }, | ||
'Lives without dependencies'; | ||
|
||
is_deeply +{ | ||
validate_with( | ||
params => [ foo => 'foo', bar => 'bar', optional => 1 ], | ||
spec => $spec, | ||
dependencies => all_of(qw( foo optional )), | ||
) | ||
}, | ||
{ foo => 'foo', bar => 'bar', optional => 1 }, | ||
'Lives when dependency is met'; |