6 use Test::More tests => 21;
10 use_ok("Moose::Util::TypeConstraints");
11 use_ok('Moose::Meta::TypeConstraint::Parameterized');
15 subtype 'AlphaKeyHash' => as 'HashRef'
17 # no keys match non-alpha
18 (grep { /[^a-zA-Z]/ } keys %$_) == 0
20 } '... created the subtype special okay';
23 subtype 'Trihash' => as 'AlphaKeyHash'
27 } '... created the subtype special okay';
30 subtype 'Noncon' => as 'Item';
31 } '... created the subtype special okay';
34 my $t = find_type_constraint('AlphaKeyHash');
35 isa_ok($t, 'Moose::Meta::TypeConstraint');
37 is($t->name, 'AlphaKeyHash', '... name is correct');
40 isa_ok($p, 'Moose::Meta::TypeConstraint');
42 is($p->name, 'HashRef', '... parent name is correct');
44 ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
45 ok(!$t->check({ one1 => 1, two2 => 2 }), '... validated it correctly');
48 my $hoi = Moose::Meta::TypeConstraint::Parameterized->new(
49 name => 'AlphaKeyHash[Int]',
50 parent => find_type_constraint('AlphaKeyHash'),
51 type_parameter => find_type_constraint('Int'),
54 ok($hoi->check({ one => 1, two => 2 }), '... validated it correctly');
55 ok(!$hoi->check({ one1 => 1, two2 => 2 }), '... validated it correctly');
56 ok(!$hoi->check({ one => 'uno', two => 'dos' }), '... validated it correctly');
57 ok(!$hoi->check({ one1 => 'un', two2 => 'deux' }), '... validated it correctly');
59 my $th = Moose::Meta::TypeConstraint::Parameterized->new(
60 name => 'Trihash[Bool]',
61 parent => find_type_constraint('Trihash'),
62 type_parameter => find_type_constraint('Bool'),
65 ok(!$th->check({ one => 1, two => 1 }), '... validated it correctly');
66 ok($th->check({ one => 1, two => 0, three => 1 }), '... validated it correctly');
67 ok(!$th->check({ one => 1, two => 2, three => 1 }), '... validated it correctly');
68 ok(!$th->check({foo1 => 1, bar2 => 0, baz3 => 1}), '... validated it correctly');
71 Moose::Meta::TypeConstraint::Parameterized->new(
73 parent => find_type_constraint('Str'),
74 type_parameter => find_type_constraint('Int'),
76 } 'non-containers cannot be parameterized';
79 Moose::Meta::TypeConstraint::Parameterized->new(
80 name => 'Noncon[Int]',
81 parent => find_type_constraint('Noncon'),
82 type_parameter => find_type_constraint('Int'),
84 } 'non-containers cannot be parameterized';