From: Shawn M Moore Date: Fri, 27 Jun 2008 04:23:03 +0000 (+0000) Subject: More tests for clone X-Git-Tag: 0.19~268 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4661ee61ba5b1442593968e49c8240c2619fb744;p=gitmo%2FMouse.git More tests for clone --- diff --git a/t/031-clone.t b/t/031-clone.t index 1f5cc50..fd9e500 100644 --- a/t/031-clone.t +++ b/t/031-clone.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 9; use Test::Exception; do { @@ -19,21 +19,35 @@ do { is => "rw", ); + has baz => ( + is => 'rw', + init_arg => undef, + ); + + has quux => ( + is => 'rw', + init_arg => 'quuux', + ); + sub clone { my ($self, @args) = @_; $self->meta->clone_object($self, @args); } }; -my $foo = Foo->new(bar => [ 1, 2, 3 ]); +my $foo = Foo->new(bar => [ 1, 2, 3 ], quuux => "indeed"); is($foo->foo, "foo", "attr 1",); +is($foo->quux, "indeed", "init_arg respected"); is_deeply($foo->bar, [ 1 .. 3 ], "attr 2"); +$foo->baz("foo"); -my $clone = $foo->clone(foo => "dancing"); +my $clone = $foo->clone(foo => "dancing", baz => "bar", quux => "nope", quuux => "yes"); is($clone->foo, "dancing", "overridden attr"); is_deeply($clone->bar, [ 1 .. 3 ], "clone attr"); +is($clone->baz, "foo", "init_arg=undef means the attr is ignored"); +is($clone->quux, "yes", "clone uses init_arg and not attribute name"); throws_ok { Foo->meta->clone_object("constant");