Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demonstration of tests using is_type()
- Loading branch information
1 parent
37ea48d
commit 2edab74
Showing
1 changed file
with
31 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use strict; | ||
use warnings FATAL => 'all'; | ||
|
||
use Test::More tests => 2; | ||
use Test::Deep; | ||
use Test::Deep::Type; | ||
|
||
{ | ||
package TypeHi; | ||
sub validate | ||
{ | ||
my ($self, $val) = @_; | ||
return "undef is not a 'hi'" if not defined $val; | ||
return undef if $val eq 'hi'; # validated: no error | ||
"'$val' is not a 'hi'"; | ||
} | ||
} | ||
sub TypeHi { bless {}, 'TypeHi' } | ||
|
||
cmp_deeply( | ||
{ greeting => 'hi' }, | ||
{ greeting => is_type(TypeHi) }, | ||
'hi validates as a TypeHi', | ||
); | ||
|
||
cmp_deeply( | ||
{ greeting => 'hello' }, | ||
{ greeting => is_type(TypeHi) }, | ||
'hello validates as a TypeHi?', | ||
); | ||
|