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};
12 use Scalar::Util qw(refaddr);
15 use_ok('Mouse::Util::TypeConstraints');
18 # subtype 'aliasing' ...
21 subtype 'Numb3rs' => as 'Num';
22 } '... create bare subtype fine';
24 my $numb3rs = find_type_constraint('Numb3rs');
25 isa_ok($numb3rs, 'Mouse::Meta::TypeConstraint');
30 package Test::Mouse::Meta::TypeConstraint;
32 use overload '""' => sub {'Broken|Test'}, fallback => 1;
35 extends 'Mouse::Meta::TypeConstraint';
38 my $dummy_instance = Test::Mouse::Meta::TypeConstraint->new;
40 ok $dummy_instance => "Created Instance";
42 isa_ok $dummy_instance,
43 'Test::Mouse::Meta::TypeConstraint' => 'isa correct type';
45 is "$dummy_instance", "Broken|Test" =>
46 'Got expected stringification result';
48 my $subtype1 = subtype 'New1' => as $dummy_instance;
50 ok $subtype1 => 'made a subtype from our type object';
52 my $subtype2 = subtype 'New2' => as $subtype1;
54 ok $subtype2 => 'made a subtype of our subtype';
59 my $type = find_type_constraint('Num');
61 my $ok_1 = eval { $type->assert_valid(1); };
62 ok($ok_1, "we can assert_valid that 1 is of type $type");
64 my $ok_2 = eval { $type->assert_valid('foo'); };
66 ok(! $ok_2, "'foo' is not of type $type");
69 qr{validation failed for .\Q$type\E.}i,
70 "correct error thrown"
75 for my $t (qw(Bar Foo)) {
76 my $tc = Mouse::Meta::TypeConstraint->new({
80 Mouse::Util::TypeConstraints::register_type_constraint($tc);
83 my $foo = Mouse::Util::TypeConstraints::find_type_constraint('Foo');
84 my $bar = Mouse::Util::TypeConstraints::find_type_constraint('Bar');
86 ok(!$foo->equals($bar), "Foo type is not equal to Bar type");
87 ok( $foo->equals($foo), "Foo equals Foo");
88 ok( 0+$foo == refaddr($foo), "overloading works");
91 ok $subtype1, "type constraint boolean overload works";