2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
14 use_ok('Mouse::Util::TypeConstraints');
21 has 'array' => (is => 'ro');
22 has 'hash' => (is => 'ro');
27 => where { $_->isa('HTTPHeader') };
31 => via { HTTPHeader->new(array => $_[0]) }
33 => via { HTTPHeader->new(hash => $_[0]) };
36 Mouse::Util::TypeConstraints->export_type_constraints_as_functions();
38 my $header = HTTPHeader->new();
39 isa_ok($header, 'HTTPHeader');
41 ok(Header($header), '... this passed the type test');
42 ok(!Header([]), '... this did not pass the type test');
43 ok(!Header({}), '... this did not pass the type test');
45 my $anon_type = subtype Object => where { $_->isa('HTTPHeader') };
50 => via { HTTPHeader->new(array => $_[0]) }
52 => via { HTTPHeader->new(hash => $_[0]) };
53 } 'coercion of anonymous subtype succeeds';
55 foreach my $coercion (
56 find_type_constraint('Header')->coercion,
60 isa_ok($coercion, 'Mouse::Meta::TypeCoercion');
63 my $coerced = $coercion->coerce([ 1, 2, 3 ]);
64 isa_ok($coerced, 'HTTPHeader');
69 '... got the right array');
70 is($coerced->hash(), undef, '... nothing assigned to the hash');
74 my $coerced = $coercion->coerce({ one => 1, two => 2, three => 3 });
75 isa_ok($coerced, 'HTTPHeader');
79 { one => 1, two => 2, three => 3 },
80 '... got the right hash');
81 is($coerced->array(), undef, '... nothing assigned to the array');
85 my $scalar_ref = \(my $var);
86 my $coerced = $coercion->coerce($scalar_ref);
87 is($coerced, $scalar_ref, '... got back what we put in');
91 my $coerced = $coercion->coerce("Foo");
92 is($coerced, "Foo", '... got back what we put in');
96 subtype 'StrWithTrailingX'
100 coerce 'StrWithTrailingX'
104 my $tc = find_type_constraint('StrWithTrailingX');
105 is($tc->coerce("foo"), "fooX", "coerce when needed");
106 is($tc->coerce("fooX"), "fooX", "do not coerce when unneeded");