Document how to pass new attribute values at instance-role application time
[gitmo/Moose.git] / t / type_constraints / union_is_a_type_of.t
CommitLineData
a93d14d1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::Fatal;
7use Test::More;
8
9use Moose::Util::TypeConstraints 'find_type_constraint';
10
11use Moose::Meta::TypeConstraint::Union;
12
13my ( $item, $int, $classname, $num )
14 = map { find_type_constraint($_) } qw{Item Int ClassName Num};
15
16ok( $int->is_subtype_of($item), 'Int is subtype of Item' );
17ok( $classname->is_subtype_of($item), 'ClassName is subtype of Item' );
18ok(
19 ( not $int->is_subtype_of($classname) ),
20 'Int is not subtype of ClassName'
21);
22ok(
23 ( not $classname->is_subtype_of($int) ),
24 'ClassName is not subtype of Int'
25);
26
27my $union = Moose::Meta::TypeConstraint::Union->new(
28 type_constraints => [ $int, $classname ] );
29
30my @domain_values = qw( 85439 Moose::Meta::TypeConstraint );
31is(
32 exception { $union->assert_valid($_) },
33 undef,
34 qq{Union accepts "$_".}
35) for @domain_values;
36
37ok(
38 $union->is_subtype_of( find_type_constraint($_) ),
39 "Int|ClassName is a subtype of $_"
40) for qw{Item Defined Value Str};
41
42ok(
43 ( not $union->is_subtype_of( find_type_constraint($_) ) ),
44 "Int|ClassName is not a subtype of $_"
45) for qw{Num Int ClassName};
46
47ok(
48 ( not $union->is_a_type_of( find_type_constraint($_) ) ),
49 "Int|ClassName is not a type of $_"
50) for qw{Int ClassName};
51done_testing;