From: gfx Date: Wed, 19 Aug 2009 02:31:23 +0000 (+0900) Subject: Add tests for testing accessor contexts X-Git-Tag: 0.89_01~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f9cf947d9d919f0524b93fd541dd1cac4a1ea28d;p=gitmo%2FMoose.git Add tests for testing accessor contexts --- diff --git a/t/020_attributes/029_accessor_context.t b/t/020_attributes/029_accessor_context.t new file mode 100755 index 0000000..a024af5 --- /dev/null +++ b/t/020_attributes/029_accessor_context.t @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More tests => 14; +use Test::Exception; + +lives_ok { + package My::Class; + use Moose; + + has s_rw => ( + is => 'rw', + ); + + has s_ro => ( + is => 'ro', + ); + + has a_rw => ( + is => 'rw', + isa => 'ArrayRef', + + auto_deref => 1, + ); + + has a_ro => ( + is => 'ro', + isa => 'ArrayRef', + + auto_deref => 1, + ); + + has h_rw => ( + is => 'rw', + isa => 'HashRef', + + auto_deref => 1, + ); + + has h_ro => ( + is => 'ro', + isa => 'HashRef', + + auto_deref => 1, + ); +} 'class definition'; + +lives_ok { + my $o = My::Class->new(); + + is_deeply [scalar $o->s_rw], [undef], 'uninitialized scalar attribute/rw in scalar context'; + is_deeply [$o->s_rw], [undef], 'uninitialized scalar attribute/rw in list context'; + is_deeply [scalar $o->s_ro], [undef], 'uninitialized scalar attribute/ro in scalar context'; + is_deeply [$o->s_ro], [undef], 'uninitialized scalar attribute/ro in list context'; + + + is_deeply [scalar $o->a_rw], [undef], 'uninitialized ArrayRef attribute/rw in scalar context'; + is_deeply [$o->a_rw], [], 'uninitialized ArrayRef attribute/rw in list context'; + is_deeply [scalar $o->a_ro], [undef], 'uninitialized ArrayRef attribute/ro in scalar context'; + is_deeply [$o->a_ro], [], 'uninitialized ArrayRef attribute/ro in list context'; + + is_deeply [scalar $o->h_rw], [undef], 'uninitialized HashRef attribute/rw in scalar context'; + is_deeply [$o->h_rw], [], 'uninitialized HashRef attribute/rw in list context'; + is_deeply [scalar $o->h_ro], [undef], 'uninitialized HashRef attribute/ro in scalar context'; + is_deeply [$o->h_ro], [], 'uninitialized HashRef attribute/ro in list context'; + +} 'testing';