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