summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-06-30 00:25:20 -0500
committerJesse Luehrs <doy@tozt.net>2010-06-30 00:25:20 -0500
commitc388fb9ba415d6543cff51aa35677f092cc0be93 (patch)
tree507d2b37e2ccfd789068c24fec5fd4c173f4ed29 /t
parent8db254e9ec91b4c0bc1990f51482059ef55fc433 (diff)
downloadmoosex-arrayref-master.tar.gz
moosex-arrayref-master.zip
basic implementationHEADmaster
Diffstat (limited to 't')
-rw-r--r--t/01-basic.t53
1 files changed, 53 insertions, 0 deletions
diff --git a/t/01-basic.t b/t/01-basic.t
new file mode 100644
index 0000000..2d75e59
--- /dev/null
+++ b/t/01-basic.t
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Scalar::Util qw(reftype);
+
+{
+ package Foo;
+ use Moose;
+ use MooseX::ArrayRef;
+
+ has foo => (is => 'rw');
+ has bar => (is => 'ro', lazy_build => 1);
+ sub _build_bar { 'BAR' }
+}
+
+my $foo = Foo->new;
+is(reftype($foo), 'ARRAY', "got an array instance");
+isa_ok($foo, 'Foo');
+ok(!$foo->has_bar, "bar not initialized yet");
+is($foo->bar, 'BAR', "lazy-built properly");
+ok($foo->has_bar, "bar initialized now");
+is($foo->foo, undef, "foo not initialized yet");
+$foo->foo('FOO');
+is($foo->foo, 'FOO', "foo initialized now");
+my @contents = @$foo;
+is_deeply(\@$foo, ['FOO', 'BAR'], "got the right instance data");
+
+{
+ package Bar;
+ use Moose;
+ extends 'Foo';
+
+ has baz => (is => 'rw');
+}
+
+my $bar = Bar->new;
+is(reftype($bar), 'ARRAY', "got an array instance");
+isa_ok($bar, 'Bar');
+isa_ok($bar, 'Foo');
+ok(!$bar->has_bar, "bar not initialized yet");
+is($bar->bar, 'BAR', "lazy-built properly");
+ok($bar->has_bar, "bar initialized now");
+is($bar->foo, undef, "foo not initialized yet");
+$bar->foo('FOO');
+is($bar->foo, 'FOO', "foo initialized now");
+is($bar->baz, undef, "baz not initialized yet");
+$bar->baz('BAZ');
+is($bar->baz, 'BAZ', "baz initialized now");
+is_deeply(\@$bar, ['FOO', 'BAR', 'BAZ'], "got the right instance data");
+
+done_testing;