summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-16 09:56:50 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-16 09:56:50 -0500
commit1a536f9127cd6c9b28000f6de00dfdbe21793224 (patch)
tree122a6ffeb4482dda1de58babced322b7f33dee6b /t
parent2a5b6f7d3dc3a2afdf5efb254720bd1b1fafcc4a (diff)
downloadbread-board-declare-1a536f9127cd6c9b28000f6de00dfdbe21793224.tar.gz
bread-board-declare-1a536f9127cd6c9b28000f6de00dfdbe21793224.zip
more tests
Diffstat (limited to 't')
-rw-r--r--t/50-infer.t172
1 files changed, 168 insertions, 4 deletions
diff --git a/t/50-infer.t b/t/50-infer.t
index d3bd1cc..88fcb68 100644
--- a/t/50-infer.t
+++ b/t/50-infer.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More;
+use Test::Fatal;
{
package Foo;
@@ -36,6 +37,118 @@ use Test::More;
use Bread::Board::Declare;
has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ block => sub { Foo->new },
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ );
+
+ has baz => (
+ is => 'ro',
+ isa => 'Baz',
+ );
+}
+
+{
+ my $c = My::Container->new;
+ isa_ok($c->baz, 'Baz');
+ isa_ok($c->baz->foo, 'Foo');
+ isa_ok($c->baz->bar, 'Bar');
+}
+
+{
+ package Baz2;
+ use Moose;
+
+ extends 'Baz';
+
+ has thing => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+ );
+}
+
+{
+ package My::Container2;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ );
+
+ has baz => (
+ is => 'ro',
+ isa => 'Baz2',
+ );
+}
+
+{
+ like(
+ exception { My::Container2->new },
+ qr/^Only class types, role types, or subtypes of Object can be inferred\. I don't know what to do with type \(Str\)/,
+ "correct error when not everything can be inferred"
+ );
+}
+
+{
+ package My::Container3;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ );
+
+ has thing => (
+ is => 'ro',
+ isa => 'Str',
+ value => 'THING',
+ );
+
+ has baz => (
+ is => 'ro',
+ isa => 'Baz2',
+ dependencies => ['thing'],
+ );
+}
+
+{
+ my $c = My::Container3->new;
+ isa_ok($c->baz, 'Baz2');
+ isa_ok($c->baz->foo, 'Foo');
+ isa_ok($c->baz->bar, 'Bar');
+ is($c->baz->thing, 'THING', "partial dependency specification works");
+}
+
+{
+ package My::Container4;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ );
+
+ has other_foo => (
is => 'ro',
isa => 'Foo',
);
@@ -51,9 +164,60 @@ use Test::More;
);
}
-my $c = My::Container->new;
-isa_ok($c->baz, 'Baz');
-isa_ok($c->baz->foo, 'Foo');
-isa_ok($c->baz->bar, 'Bar');
+{
+ like(
+ exception { My::Container4->new },
+ qr/^You have already declared a typemap for type Foo/,
+ "correct error when inferring is ambiguous"
+ );
+}
+
+{
+ package Foo2;
+ use Moose;
+
+ extends 'Foo';
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ required => 1,
+ );
+}
+
+{
+ package My::Container5;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Foo2',
+ );
+
+ has other_foo => (
+ is => 'ro',
+ isa => 'Foo2',
+ typemap => 0,
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ );
+
+ has baz => (
+ is => 'ro',
+ isa => 'Baz',
+ );
+}
+
+{
+ my $c = My::Container5->new;
+ isa_ok($c->baz, 'Baz');
+ isa_ok($c->baz->foo, 'Foo');
+ isa_ok($c->baz->bar, 'Bar');
+ isa_ok($c->other_foo->bar, 'Bar');
+}
done_testing;