From: gfx Date: Fri, 4 Dec 2009 04:15:34 +0000 (+0900) Subject: Add tests for magical vars and hash iterators X-Git-Tag: 0.41~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=24dd8fef0e410b79a65dc3faa1a6cacf5719e386 Add tests for magical vars and hash iterators --- diff --git a/t/001_mouse/043-parameterized-type.t b/t/001_mouse/043-parameterized-type.t index 6eaeddd..74b3ea9 100644 --- a/t/001_mouse/043-parameterized-type.t +++ b/t/001_mouse/043-parameterized-type.t @@ -1,9 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 46; +use Test::More tests => 51; use Test::Exception; +use Tie::Hash; +use Tie::Array; { { package My::Role; @@ -183,4 +185,29 @@ ok $x->check([[10, undef]]); ok!$x->check([[10, 3.14]]); ok!$x->check({}); +$x = tie my @ta, 'Tie::StdArray'; +my $array_of_int = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Int]'); + +@$x = (1, 2, 3); +ok $array_of_int->check(\@ta), 'magical array'; + +@$x = (1, 2, 3.14); +ok !$array_of_int->check(\@ta); + +$x = tie my %th, 'Tie::StdHash'; + +my $hash_of_int = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('HashRef[Int]'); + +%$x = (foo => 1, bar => 3, baz => 5); +ok $hash_of_int->check(\%th), 'magical hash'; + +$x->{foo} = 3.14; +ok!$hash_of_int->check(\%th); + +my %th_clone; +while(my($k, $v) = each %th){ + $th_clone{$k} = $v; +} + +is_deeply \%th_clone, \%th, 'the hash iterator is initialized';