Skip to content

Commit

Permalink
Add tests for coercion support.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafl committed Feb 21, 2009
1 parent 0653f38 commit f2fec99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions t/basic.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 27;
use Test::More tests => 29;
use Test::Exception;

use FindBin;
Expand Down Expand Up @@ -40,6 +40,7 @@ dies_ok(sub { $o->affe('foo') });

dies_ok(sub { $o->named });
dies_ok(sub { $o->named(optional => 42) });

{
local $TODO = 'no useful error messages yet';
throws_ok(sub { $o->named }, qr/\b at \b .* \b line \b \d+/x, "dies with proper exception");
Expand Down Expand Up @@ -69,6 +70,9 @@ lives_ok(sub {
);
});

lives_ok(sub { $o->with_coercion({}) });
dies_ok(sub { $o->without_coercion({}) });

# MooseX::Meta::Signature::Combined bug? optional positional can't be omitted
#lives_ok(sub { $o->combined(1, 2, required => 3) });
#lives_ok(sub { $o->combined(1, 2, required => 3, optional => 4) });
Expand All @@ -77,4 +81,3 @@ use MooseX::Method::Signatures;

my $anon = method ($foo, $bar) { };
isa_ok($anon, 'Moose::Meta::Method');

12 changes: 12 additions & 0 deletions t/lib/TestClass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package TestClass;

use Moose;
use MooseX::Method::Signatures;
use Moose::Util::TypeConstraints;

method new ($class: Str $foo, Int $bar = 42
where { $_ % 2 == 0 }
Expand Down Expand Up @@ -35,6 +36,17 @@ method combined ($a, $b, $c?, :$optional, :$required!) {
return ($a, $b, $c, $optional, $required);
}

BEGIN {
class_type 'MyType';

coerce 'MyType',
from 'HashRef',
via { bless { %{$_} } => 'MyType' };
}

method without_coercion (MyType $foo) { $foo }
method with_coercion (MyType $foo does coerce) { $foo }

no Moose;

1;

0 comments on commit f2fec99

Please sign in to comment.