Navigation Menu

Skip to content

Commit

Permalink
demonstration of tests using is_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge committed Feb 25, 2013
1 parent 37ea48d commit 2edab74
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/demo.t
@@ -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?',
);

0 comments on commit 2edab74

Please sign in to comment.