Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 040_type_constraints / 017_subtyping_union_types.t
CommitLineData
346a3ab8 1#!/usr/bin/perl
5a592ad7 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
346a3ab8 5
6use strict;
7use warnings;
8
5a592ad7 9use Test::More;
346a3ab8 10use Test::Exception;
11
12BEGIN {
13 use_ok("Mouse::Util::TypeConstraints");
14}
15
16lives_ok {
17 subtype 'MyCollections' => as 'ArrayRef | HashRef';
18} '... created the subtype special okay';
19
20{
21 my $t = find_type_constraint('MyCollections');
22 isa_ok($t, 'Mouse::Meta::TypeConstraint');
23
24 is($t->name, 'MyCollections', '... name is correct');
25
26 my $p = $t->parent;
5a592ad7 27 isa_ok($p, 'Mouse::Meta::TypeConstraint');
346a3ab8 28 isa_ok($p, 'Mouse::Meta::TypeConstraint');
29
30 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
31
32 ok($t->check([]), '... validated it correctly');
33 ok($t->check({}), '... validated it correctly');
34 ok(!$t->check(1), '... validated it correctly');
35}
36
37lives_ok {
38 subtype 'MyCollectionsExtended'
39 => as 'ArrayRef|HashRef'
40 => where {
41 if (ref($_) eq 'ARRAY') {
42 return if scalar(@$_) < 2;
43 }
44 elsif (ref($_) eq 'HASH') {
45 return if scalar(keys(%$_)) < 2;
46 }
47 1;
48 };
49} '... created the subtype special okay';
50
51{
52 my $t = find_type_constraint('MyCollectionsExtended');
53 isa_ok($t, 'Mouse::Meta::TypeConstraint');
54
55 is($t->name, 'MyCollectionsExtended', '... name is correct');
56
57 my $p = $t->parent;
5a592ad7 58 isa_ok($p, 'Mouse::Meta::TypeConstraint');
346a3ab8 59 isa_ok($p, 'Mouse::Meta::TypeConstraint');
60
61 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
62
63 ok(!$t->check([]), '... validated it correctly');
64 ok($t->check([1, 2]), '... validated it correctly');
65
66 ok(!$t->check({}), '... validated it correctly');
67 ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
68
69 ok(!$t->check(1), '... validated it correctly');
70}
71
5a592ad7 72done_testing;