Commit | Line | Data |
92b3c73c |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 41; |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose::Util::TypeConstraints'); |
11 | } |
12 | |
13 | my $Str = find_type_constraint('Str'); |
14 | my $Undef = find_type_constraint('Undef'); |
15 | my $Item = find_type_constraint('Item'); |
16 | my $Value = find_type_constraint('Value'); |
17 | my $ClassName = find_type_constraint('ClassName'); |
18 | my $Num = find_type_constraint('Num'); |
19 | my $Int = find_type_constraint('Int'); |
20 | |
21 | for my $type ($Str, $Undef, $Item, $Value, $ClassName, $Num, $Int) { |
22 | isa_ok($type, 'Moose::Meta::TypeConstraint'); |
23 | } |
24 | |
25 | my $Str_or_Undef = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Str, $Undef]); |
26 | my $Value_or_Undef = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Value, $Undef]); |
27 | my $Int_or_ClassName = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Int, $ClassName]); |
28 | |
29 | for my $type ($Str_or_Undef, $Value_or_Undef, $Int_or_ClassName) { |
30 | isa_ok($type, 'Moose::Meta::TypeConstraint::Union'); |
31 | } |
32 | |
33 | ok($Str_or_Undef->includes_type($Str), "Str | Undef includes Str"); |
34 | ok($Str_or_Undef->includes_type($Undef), "Str | Undef includes Undef"); |
35 | ok(!$Str_or_Undef->includes_type($Item), "Str | Undef doesn't include supertype Item"); |
36 | ok(!$Str_or_Undef->includes_type($Value), "Str | Undef doesn't include supertype Value"); |
37 | ok($Str_or_Undef->includes_type($ClassName), "Str | Undef includes Str subtype ClassName"); |
38 | ok(!$Str_or_Undef->includes_type($Num), "Str | Undef doesn't include Num"); |
39 | ok(!$Str_or_Undef->includes_type($Int), "Str | Undef doesn't include Int"); |
40 | ok(!$Str_or_Undef->includes_type($Value_or_Undef), "Str | Undef doesn't include supertype Value | Undef"); |
41 | ok($Str_or_Undef->includes_type($Str_or_Undef), "Str | Undef includes Str | Undef"); |
42 | ok(!$Str_or_Undef->includes_type($Int_or_ClassName), "Str | Undef doesn't include Int | ClassName"); |
43 | |
44 | ok($Value_or_Undef->includes_type($Value), "Value | Undef includes Value"); |
45 | ok($Value_or_Undef->includes_type($Undef), "Value | Undef includes Undef"); |
46 | ok(!$Value_or_Undef->includes_type($Item), "Value | Undef doesn't include supertype Item"); |
47 | ok($Value_or_Undef->includes_type($Str), "Value | Undef includes subtype Str"); |
48 | ok($Value_or_Undef->includes_type($ClassName), "Value | Undef includes subtype ClassName"); |
49 | ok($Value_or_Undef->includes_type($Num), "Value | Undef includes subtype Num"); |
50 | ok($Value_or_Undef->includes_type($Int), "Value | Undef includes subtype Int"); |
51 | ok($Value_or_Undef->includes_type($Str_or_Undef), "Value | Undef includes Str | Undef"); |
52 | ok($Value_or_Undef->includes_type($Value_or_Undef), "Value | Undef includes Value | Undef"); |
53 | ok($Value_or_Undef->includes_type($Int_or_ClassName), "Value | Undef includes Int | ClassName"); |
54 | |
55 | ok($Int_or_ClassName->includes_type($Int), "Int | ClassName includes Int"); |
56 | ok($Int_or_ClassName->includes_type($ClassName), "Int | ClassName includes ClassName"); |
57 | ok(!$Int_or_ClassName->includes_type($Str), "Int | ClassName doesn't include supertype Str"); |
58 | ok(!$Int_or_ClassName->includes_type($Undef), "Int | ClassName doesn't include Undef"); |
59 | ok(!$Int_or_ClassName->includes_type($Item), "Int | ClassName doesn't include supertype Item"); |
60 | ok(!$Int_or_ClassName->includes_type($Value), "Int | ClassName doesn't include supertype Value"); |
61 | ok(!$Int_or_ClassName->includes_type($Num), "Int | ClassName doesn't include supertype Num"); |
62 | ok(!$Int_or_ClassName->includes_type($Str_or_Undef), "Int | ClassName doesn't include Str | Undef"); |
63 | ok(!$Int_or_ClassName->includes_type($Value_or_Undef), "Int | ClassName doesn't include Value | Undef"); |
64 | ok($Int_or_ClassName->includes_type($Int_or_ClassName), "Int | ClassName includes Int | ClassName"); |
65 | |