Cleanup failing tests
[gitmo/Mouse.git] / Moose-t-failing / 040_type_constraints / 012_container_type_coercion.t
diff --git a/Moose-t-failing/040_type_constraints/012_container_type_coercion.t b/Moose-t-failing/040_type_constraints/012_container_type_coercion.t
new file mode 100644 (file)
index 0000000..b94c1ed
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+# This is automatically generated by author/import-moose-test.pl.
+# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
+use t::lib::MooseCompat;
+
+use strict;
+use warnings;
+
+use Test::More;
+$TODO = q{Mouse is not yet completed};
+use Test::Exception;
+
+BEGIN {
+    use_ok('Mouse::Util::TypeConstraints');
+    use_ok('Mouse::Meta::TypeConstraint');
+}
+
+my $r = Mouse::Util::TypeConstraints->get_type_constraint_registry;
+
+# Array of Ints
+
+my $array_of_ints = Mouse::Meta::TypeConstraint->new(
+    name           => 'ArrayRef[Int]',
+    parent         => find_type_constraint('ArrayRef'),
+    type_parameter => find_type_constraint('Int'),
+);
+isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
+isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
+
+$r->add_type_constraint($array_of_ints);
+
+is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added');
+
+# Hash of Ints
+
+my $hash_of_ints = Mouse::Meta::TypeConstraint->new(
+    name           => 'HashRef[Int]',
+    parent         => find_type_constraint('HashRef'),
+    type_parameter => find_type_constraint('Int'),
+);
+isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
+isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
+
+$r->add_type_constraint($hash_of_ints);
+
+is(find_type_constraint('HashRef[Int]'), $hash_of_ints, '... found the type we just added');
+
+## now attempt a coercion
+
+{
+    package Foo;
+    use Mouse;
+    use Mouse::Util::TypeConstraints;
+
+    coerce 'ArrayRef[Int]'
+        => from 'HashRef[Int]'
+            => via { [ values %$_ ] };
+
+    has 'bar' => (
+        is     => 'ro',
+        isa    => 'ArrayRef[Int]',
+        coerce => 1,
+    );
+
+}
+
+my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 });
+isa_ok($foo, 'Foo');
+
+is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!');
+
+done_testing;