From: Dave Rolsky Date: Sat, 18 Sep 2010 16:11:24 +0000 (-0500) Subject: Add some tests for trigger on array changes X-Git-Tag: 1.15~137 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ccd17aa9292ffde22d704923fc9a01c35501f5d0;p=gitmo%2FMoose.git Add some tests for trigger on array changes --- diff --git a/t/070_native_traits/012_array_trigger.t b/t/070_native_traits/012_array_trigger.t new file mode 100644 index 0000000..a659025 --- /dev/null +++ b/t/070_native_traits/012_array_trigger.t @@ -0,0 +1,54 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +{ + package Foo; + use Moose; + + our @TriggerArgs; + + has array => ( + traits => ['Array'], + is => 'rw', + isa => 'ArrayRef', + handles => { + push_array => 'push', + set_array => 'set', + }, + clearer => 'clear_array', + trigger => sub { @TriggerArgs = @_ }, + ); +} + +my $foo = Foo->new; + +{ + $foo->array( [ 1, 2, 3 ] ); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, [ 1, 2, 3 ] ], + 'trigger was called for normal writer' + ); + + $foo->push_array(5); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, [ 1, 2, 3, 5 ], [ 1, 2, 3 ] ], + 'trigger was called on push' + ); + + $foo->set_array( 1, 42 ); + + is_deeply( + \@Foo::TriggerArgs, + [ $foo, [ 1, 42, 3, 5 ], [ 1, 2, 3, 5 ] ], + 'trigger was called on set' + ); +} + +done_testing;