Remove references to jules git repo
[gitmo/Moose.git] / t / 040_type_constraints / 017_subtyping_union_types.t
CommitLineData
8de73ff1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
2c78d811 6use Test::More tests => 21;
8de73ff1 7use Test::Exception;
8
9BEGIN {
10 use_ok("Moose::Util::TypeConstraints");
11}
12
13lives_ok {
14 subtype 'MyCollections' => as 'ArrayRef | HashRef';
15} '... created the subtype special okay';
16
17{
18 my $t = find_type_constraint('MyCollections');
19 isa_ok($t, 'Moose::Meta::TypeConstraint');
20
21 is($t->name, 'MyCollections', '... name is correct');
22
23 my $p = $t->parent;
24 isa_ok($p, 'Moose::Meta::TypeConstraint::Union');
25 isa_ok($p, 'Moose::Meta::TypeConstraint');
26
eb4c4e82 27 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
8de73ff1 28
29 ok($t->check([]), '... validated it correctly');
d03bd989 30 ok($t->check({}), '... validated it correctly');
8de73ff1 31 ok(!$t->check(1), '... validated it correctly');
32}
33
34lives_ok {
d03bd989 35 subtype 'MyCollectionsExtended'
eb4c4e82 36 => as 'ArrayRef|HashRef'
8de73ff1 37 => where {
38 if (ref($_) eq 'ARRAY') {
39 return if scalar(@$_) < 2;
40 }
41 elsif (ref($_) eq 'HASH') {
d03bd989 42 return if scalar(keys(%$_)) < 2;
8de73ff1 43 }
44 1;
45 };
46} '... created the subtype special okay';
47
48{
49 my $t = find_type_constraint('MyCollectionsExtended');
50 isa_ok($t, 'Moose::Meta::TypeConstraint');
51
52 is($t->name, 'MyCollectionsExtended', '... name is correct');
53
54 my $p = $t->parent;
55 isa_ok($p, 'Moose::Meta::TypeConstraint::Union');
56 isa_ok($p, 'Moose::Meta::TypeConstraint');
57
eb4c4e82 58 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
8de73ff1 59
60 ok(!$t->check([]), '... validated it correctly');
d03bd989 61 ok($t->check([1, 2]), '... validated it correctly');
62
63 ok(!$t->check({}), '... validated it correctly');
64 ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
65
8de73ff1 66 ok(!$t->check(1), '... validated it correctly');
67}
68
69