summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-02-21 01:07:16 -0600
committerJesse Luehrs <doy@tozt.net>2011-02-21 01:07:16 -0600
commiteeb792decae28e85e487ebeeb6d56f1994b56c62 (patch)
tree844c44da6a4e81639c59a3d4e521bafa5e09af56 /t
parenteb9a0d361b37c5b3a7d750385f6b3a3300301fbc (diff)
downloadbread-board-declare-eeb792decae28e85e487ebeeb6d56f1994b56c62.tar.gz
bread-board-declare-eeb792decae28e85e487ebeeb6d56f1994b56c62.zip
handle type checks and auto_deref on values returned from services
Diffstat (limited to 't')
-rw-r--r--t/04-block.t2
-rw-r--r--t/30-type-checks.t26
-rw-r--r--t/31-auto-deref.t44
3 files changed, 71 insertions, 1 deletions
diff --git a/t/04-block.t b/t/04-block.t
index a06a950..c0f9bad 100644
--- a/t/04-block.t
+++ b/t/04-block.t
@@ -22,7 +22,7 @@ use Test::More;
has baz => (
is => 'ro',
- isa => 'Baz',
+ isa => 'Str',
block => sub {
my ($s, $self) = @_;
return $s->param('bar') . $self->foo;
diff --git a/t/30-type-checks.t b/t/30-type-checks.t
new file mode 100644
index 0000000..58f4405
--- /dev/null
+++ b/t/30-type-checks.t
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ package Foo;
+ use Moose;
+ use MooseX::Bread::Board;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Ref',
+ value => 'FOO',
+ );
+}
+
+{
+ my $foo = Foo->new;
+ like(exception { $foo->foo },
+ qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Ref' with value FOO/,
+ "error when service returns invalid value");
+}
+
+done_testing;
diff --git a/t/31-auto-deref.t b/t/31-auto-deref.t
new file mode 100644
index 0000000..c86fffd
--- /dev/null
+++ b/t/31-auto-deref.t
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+{
+ package Foo;
+ use Moose;
+ use MooseX::Bread::Board;
+
+ has foo => (
+ is => 'ro',
+ isa => 'ArrayRef',
+ auto_deref => 1,
+ block => sub { ['foo', 'bar'] },
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'HashRef',
+ auto_deref => 1,
+ block => sub { {'foo' => 'bar'} },
+ );
+}
+
+{
+ my $foo = Foo->new;
+
+ is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array");
+ is_deeply([$foo->foo], ['foo', 'bar'], "list array");
+ is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash");
+ is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash");
+}
+
+{
+ my $foo = Foo->new(foo => ['foo', 'bar'], bar => {'foo' => 'bar'});
+
+ is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array");
+ is_deeply([$foo->foo], ['foo', 'bar'], "list array");
+ is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash");
+ is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash");
+}
+
+done_testing;