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};
13 use Mouse::Util::TypeConstraints;
14 use Mouse::Meta::TypeConstraint;
17 ## Create a subclass with a custom method
20 package Test::Mouse::Meta::TypeConstraint;
22 extends 'Mouse::Meta::TypeConstraint';
24 sub my_custom_method {
29 my $Int = find_type_constraint('Int');
30 ok $Int, 'Got a good type constraint';
32 my $parent = Test::Mouse::Meta::TypeConstraint->new({
33 name => "Test::Mouse::Meta::TypeConstraint" ,
37 ok $parent, 'Created type constraint';
38 ok $parent->check(1), 'Correctly passed';
39 ok ! $parent->check('a'), 'correctly failed';
40 ok $parent->my_custom_method, 'found the custom method';
42 my $subtype1 = subtype 'another_subtype' => as $parent;
44 ok $subtype1, 'Created type constraint';
45 ok $subtype1->check(1), 'Correctly passed';
46 ok ! $subtype1->check('a'), 'correctly failed';
47 ok $subtype1->my_custom_method, 'found the custom method';
50 my $subtype2 = subtype 'another_subtype' => as $subtype1 => where { $_ < 10 };
52 ok $subtype2, 'Created type constraint';
53 ok $subtype2->check(1), 'Correctly passed';
54 ok ! $subtype2->check('a'), 'correctly failed';
55 ok ! $subtype2->check(100), 'correctly failed';
57 ok $subtype2->my_custom_method, 'found the custom method';
80 my $foo = class_type 'Foo';
81 my $isa_foo = subtype 'IsaFoo' => as $foo;
83 ok $isa_foo, 'Created subtype of Foo type';
84 ok $isa_foo->check( Foo->new ), 'Foo passes check';
85 ok $isa_foo->check( Bar->new ), 'Bar passes check';
86 ok ! $isa_foo->check( Baz->new ), 'Baz does not pass check';
87 like $foo->get_message( Baz->new ), qr/^Validation failed for 'Foo' with value Baz=HASH\(0x\w+\) \(not isa Foo\)/, 'Better validation message';
89 # Maybe in the future this *should* inherit?
90 like $isa_foo->get_message( Baz->new ), qr/^Validation failed for 'IsaFoo' with value Baz=HASH\(0x\w+\)$/, "Subtypes do not automatically inherit parent type's message";
107 } qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/;
110 Quux->new(age => (bless {}, 'Positive'));
120 } qr/^Attribute \(age\) does not pass the type constraint because: Validation failed for 'Positive' with value 3 \(not isa Positive\)/;
123 Quux->new(age => Positive->new)
126 class_type 'Negative' => message { "$_ is not a Negative Nancy" };
140 Quux::Ier->new(age => 3)
141 } qr/^Attribute \(age\) does not pass the type constraint because: 3 is not a Negative Nancy /;
144 Quux::Ier->new(age => (bless {}, 'Negative'))