X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F026-auto-deref.t;h=d4b1df512bbc8c0872878fef131ddde824bc31b0;hb=de3f9ba5c62f6e2b1cf64d057ffef60224b4204a;hp=0aa021e0a9069e59663d03999a96b04901214ae0;hpb=615d5d5fa75cb9c4d1445184b63dae565dcc790e;p=gitmo%2FMouse.git diff --git a/t/026-auto-deref.t b/t/026-auto-deref.t index 0aa021e..d4b1df5 100644 --- a/t/026-auto-deref.t +++ b/t/026-auto-deref.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 15; use Test::Exception; do { @@ -19,6 +19,21 @@ do { isa => 'HashRef', auto_deref => 1, ); + + ::throws_ok { + has any => ( + is => 'rw', + auto_deref => 1, + ); + } qr/You cannot auto-dereference without specifying a type constraint on attribute \(any\)/; + + ::throws_ok { + has scalar => ( + is => 'rw', + isa => 'Value', + auto_deref => 1, + ); + } qr/You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute \(scalar\)/; }; my $obj; @@ -40,20 +55,14 @@ lives_ok { is($obj->array, undef, "array without value is undef in scalar context"); is($obj->hash, undef, "hash without value is undef in scalar context"); -TODO: { - local $TODO = "auto_deref not implemented"; - is(@array, 0, "array without value is empty in list context"); - is(keys %hash, 0, "hash without value is empty in list context"); -}; +is(@array, 0, "array without value is empty in list context"); +is(keys %hash, 0, "hash without value is empty in list context"); @array = $obj->array([1, 2, 3]); %hash = $obj->hash({foo => 1, bar => 2}); -TODO: { - local $TODO = "auto_deref not implemented"; - is_deeply(\@array, [1, 2, 3], "setter returns the dereferenced list"); - is_deeply(\%hash, {foo => 1, bar => 2}, "setter returns the dereferenced hash"); -}; +is_deeply(\@array, [1, 2, 3], "setter returns the dereferenced list"); +is_deeply(\%hash, {foo => 1, bar => 2}, "setter returns the dereferenced hash"); lives_ok { @array = $obj->array; @@ -68,9 +77,6 @@ lives_ok { is_deeply($array, [1, 2, 3], "auto_deref in scalar context gives the reference"); is_deeply($hash, {foo => 1, bar => 2}, "auto_deref in scalar context gives the reference"); -TODO: { - local $TODO = "auto_deref not implemented"; - is_deeply(\@array, [1, 2, 3], "auto_deref in list context gives the list"); - is_deeply(\%hash, {foo => 1, bar => 2}, "auto_deref in list context gives the hash"); -}; +is_deeply(\@array, [1, 2, 3], "auto_deref in list context gives the list"); +is_deeply(\%hash, {foo => 1, bar => 2}, "auto_deref in list context gives the hash");