From: gfx Date: Thu, 12 Nov 2009 06:31:23 +0000 (+0900) Subject: Add BUILDARGS tests X-Git-Tag: 0.40_06~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ecfc2defd2955d68c9cbc3ad048ce80bd1020da;p=gitmo%2FMouse.git Add BUILDARGS tests --- diff --git a/t/001_mouse/032-buildargs.t b/t/001_mouse/032-buildargs.t index 4b286f3..49faaa8 100644 --- a/t/001_mouse/032-buildargs.t +++ b/t/001_mouse/032-buildargs.t @@ -1,7 +1,42 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 11; +use Test::Exception; + +{ + package C; + use Mouse; +} + +# original BUILDARGS + +is_deeply( C->BUILDARGS(), {} ); +is_deeply( C->BUILDARGS(foo => 42), {foo => 42} ); +is_deeply( C->BUILDARGS(foo => 42, foo => 'bar'), {foo => 'bar'} ); +is_deeply( C->BUILDARGS({foo => 1, bar => 2}), {foo => 1, bar => 2} ); + +my %hash = (foo => 10); +my $args = C->BUILDARGS(\%hash); +$args->{foo}++; +is $hash{foo}, 10, 'values must be copied'; + +%hash = (foo => 10); +$args = C->BUILDARGS(%hash); +$args->{foo}++; +is $hash{foo}, 10, 'values must be copied'; + +throws_ok { + C->BUILDARGS([]); +} qr/must be a HASH ref/; + + +throws_ok { + C->BUILDARGS([]); +} qr/must be a HASH ref/; + + +# custom BUILDARGS do { package Foo;