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;
13 use_ok("Mouse::Util::TypeConstraints");
14 use_ok('Mouse::Meta::TypeConstraint');
18 subtype 'AlphaKeyHash' => as 'HashRef'
20 # no keys match non-alpha
21 (grep { /[^a-zA-Z]/ } keys %$_) == 0
23 } '... created the subtype special okay';
26 subtype 'Trihash' => as 'AlphaKeyHash'
30 } '... created the subtype special okay';
33 subtype 'Noncon' => as 'Item';
34 } '... created the subtype special okay';
37 my $t = find_type_constraint('AlphaKeyHash');
38 isa_ok($t, 'Mouse::Meta::TypeConstraint');
40 is($t->name, 'AlphaKeyHash', '... name is correct');
43 isa_ok($p, 'Mouse::Meta::TypeConstraint');
45 is($p->name, 'HashRef', '... parent name is correct');
47 ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
48 ok(!$t->check({ one1 => 1, two2 => 2 }), '... validated it correctly');
50 local $TODO = 'Mouse does not support equals()';
51 ok( $t->equals($t), "equals to self" );
52 ok( !$t->equals($t->parent), "not equal to parent" );
55 my $hoi = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('AlphaKeyHash[Int]');
57 ok($hoi->check({ one => 1, two => 2 }), '... validated it correctly');
58 ok(!$hoi->check({ one1 => 1, two2 => 2 }), '... validated it correctly');
59 ok(!$hoi->check({ one => 'uno', two => 'dos' }), '... validated it correctly');
60 ok(!$hoi->check({ one1 => 'un', two2 => 'deux' }), '... validated it correctly');
61 { local $TODO = 'Mouse does not support equals()';
62 ok( $hoi->equals($hoi), "equals to self" );
63 ok( !$hoi->equals($hoi->parent), "equals to self" );
64 ok( !$hoi->equals(find_type_constraint('AlphaKeyHash')), "not equal to unparametrized self" );
65 ok( $hoi->equals( Mouse::Meta::TypeConstraint->new( name => "Blah", parent => find_type_constraint("AlphaKeyHash"), type_parameter => find_type_constraint("Int") ) ), "equal to clone" );
66 ok( !$hoi->equals( Mouse::Meta::TypeConstraint->new( name => "Oink", parent => find_type_constraint("AlphaKeyHash"), type_parameter => find_type_constraint("Str") ) ), "not equal to different parameter" );
69 my $th = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('Trihash[Bool]');
70 ok(!$th->check({ one => 1, two => 1 }), '... validated it correctly');
71 ok($th->check({ one => 1, two => 0, three => 1 }), '... validated it correctly');
72 ok(!$th->check({ one => 1, two => 2, three => 1 }), '... validated it correctly');
73 ok(!$th->check({foo1 => 1, bar2 => 0, baz3 => 1}), '... validated it correctly');
76 Mouse::Meta::TypeConstraint->new(
78 parent => find_type_constraint('Str'),
79 type_parameter => find_type_constraint('Int'),
81 } 'non-containers cannot be parameterized';
84 Mouse::Meta::TypeConstraint->new(
85 name => 'Noncon[Int]',
86 parent => find_type_constraint('Noncon'),
87 type_parameter => find_type_constraint('Int'),
89 } 'non-containers cannot be parameterized';