Checking in changes prior to tagging of version 0.92.
[gitmo/Mouse.git] / t / 001_mouse / 043-parameterized-type.t
index 9fb344f..e3e4cda 100644 (file)
@@ -1,7 +1,7 @@
-#!/usr/bin/env perl
+#!perl
 use strict;
 use warnings;
-use Test::More tests => 54;
+use Test::More;
 use Test::Exception;
 
 use Tie::Hash;
@@ -122,7 +122,8 @@ use Tie::Array;
         my $bar = Bar->new(list => [ qw(a b c) ]);
 
         is_deeply( $bar->list, \@list, "list is as expected");
-    } "coercion works";
+    } "coercion works"
+        or diag( Mouse::Util::TypeConstraints::find_type_constraint("Bar::List")->dump );
 
     throws_ok {
         Bar->new(list => [ { 1 => 2 }, 2, 3 ]);
@@ -222,3 +223,30 @@ else{ # under Moose
 }
 
 is_deeply \%th_clone, \%th, 'the hash iterator is initialized';
+
+{
+    my $myhashref = subtype 'MyHashRef',
+        as 'HashRef[Value]',
+        where { keys %$_ > 1 };
+
+    ok  $myhashref->is_a_type_of('HashRef'), "$myhashref";
+    ok  $myhashref->check({ a => 43, b => 100 });
+    ok  $myhashref->check({ a => 43, b => 3.14 });
+    ok !$myhashref->check({});
+    ok !$myhashref->check({ a => 42, b => [] });
+
+    is $myhashref->type_parameter, 'Value';
+
+    $myhashref = subtype 'H', as 'MyHashRef[Int]';
+
+    ok  $myhashref->is_a_type_of('HashRef'), "$myhashref";
+    ok  $myhashref->check({ a => 43, b => 100 });
+    ok !$myhashref->check({ a => 43, b => 3.14 });
+    ok !$myhashref->check({});
+    ok !$myhashref->check({ a => 42, b => [] });
+
+    is $myhashref->type_parameter, 'Int';
+}
+
+done_testing;
+