Cleanup failing tests
[gitmo/Mouse.git] / Moose-t-failing / 040_type_constraints / 008_union_types.t
CommitLineData
b2b106d7 1#!/usr/bin/perl
c47cf415 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;
b2b106d7 5
6use strict;
7use warnings;
8
c47cf415 9use Test::More;
10$TODO = q{Mouse is not yet completed};
b2b106d7 11use Test::Exception;
12
13BEGIN {
14 use_ok('Mouse::Util::TypeConstraints');
15}
16
17my $Str = find_type_constraint('Str');
18isa_ok($Str, 'Mouse::Meta::TypeConstraint');
19
20my $Undef = find_type_constraint('Undef');
21isa_ok($Undef, 'Mouse::Meta::TypeConstraint');
22
23ok(!$Str->check(undef), '... Str cannot accept an Undef value');
24ok($Str->check('String'), '... Str can accept an String value');
25ok(!$Undef->check('String'), '... Undef cannot accept an Str value');
26ok($Undef->check(undef), '... Undef can accept an Undef value');
27
c47cf415 28my $Str_or_Undef = Mouse::Meta::TypeConstraint->new(type_constraints => [$Str, $Undef]);
29isa_ok($Str_or_Undef, 'Mouse::Meta::TypeConstraint');
b2b106d7 30
31ok($Str_or_Undef->check(undef), '... (Str | Undef) can accept an Undef value');
32ok($Str_or_Undef->check('String'), '... (Str | Undef) can accept a String value');
33
34ok($Str_or_Undef->is_a_type_of($Str), "subtype of Str");
35ok($Str_or_Undef->is_a_type_of($Undef), "subtype of Undef");
36
c47cf415 37cmp_ok($Str_or_Undef->find_type_for('String'), 'eq', 'Str', 'find_type_for Str');
38cmp_ok($Str_or_Undef->find_type_for(undef), 'eq', 'Undef', 'find_type_for Undef');
39ok(!defined($Str_or_Undef->find_type_for(sub { })), 'no find_type_for CodeRef');
40
b2b106d7 41ok( !$Str_or_Undef->equals($Str), "not equal to Str" );
42ok( $Str_or_Undef->equals($Str_or_Undef), "equal to self" );
c47cf415 43ok( $Str_or_Undef->equals(Mouse::Meta::TypeConstraint->new(type_constraints => [ $Str, $Undef ])), "equal to clone" );
44ok( $Str_or_Undef->equals(Mouse::Meta::TypeConstraint->new(type_constraints => [ $Undef, $Str ])), "equal to reversed clone" );
b2b106d7 45
46ok( !$Str_or_Undef->is_a_type_of("ThisTypeDoesNotExist"), "not type of non existant type" );
47ok( !$Str_or_Undef->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of non existant type" );
48
49# another ....
50
51my $ArrayRef = find_type_constraint('ArrayRef');
52isa_ok($ArrayRef, 'Mouse::Meta::TypeConstraint');
53
54my $HashRef = find_type_constraint('HashRef');
55isa_ok($HashRef, 'Mouse::Meta::TypeConstraint');
56
57ok($ArrayRef->check([]), '... ArrayRef can accept an [] value');
58ok(!$ArrayRef->check({}), '... ArrayRef cannot accept an {} value');
59ok($HashRef->check({}), '... HashRef can accept an {} value');
60ok(!$HashRef->check([]), '... HashRef cannot accept an [] value');
61
c47cf415 62my $HashOrArray = Mouse::Meta::TypeConstraint->new(type_constraints => [$ArrayRef, $HashRef]);
63isa_ok($HashOrArray, 'Mouse::Meta::TypeConstraint');
b2b106d7 64
65ok($HashOrArray->check([]), '... (ArrayRef | HashRef) can accept []');
66ok($HashOrArray->check({}), '... (ArrayRef | HashRef) can accept {}');
67
68ok(!$HashOrArray->check(\(my $var1)), '... (ArrayRef | HashRef) cannot accept scalar refs');
69ok(!$HashOrArray->check(sub {}), '... (ArrayRef | HashRef) cannot accept code refs');
70ok(!$HashOrArray->check(50), '... (ArrayRef | HashRef) cannot accept Numbers');
71
72diag $HashOrArray->validate([]);
73
74ok(!defined($HashOrArray->validate([])), '... (ArrayRef | HashRef) can accept []');
75ok(!defined($HashOrArray->validate({})), '... (ArrayRef | HashRef) can accept {}');
76
77like($HashOrArray->validate(\(my $var2)),
c47cf415 78qr/Validation failed for \'ArrayRef\' with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' with value SCALAR\(0x.+?\) in \(ArrayRef\|HashRef\)/,
b2b106d7 79'... (ArrayRef | HashRef) cannot accept scalar refs');
80
81like($HashOrArray->validate(sub {}),
c47cf415 82qr/Validation failed for \'ArrayRef\' with value CODE\(0x.+?\) and Validation failed for \'HashRef\' with value CODE\(0x.+?\) in \(ArrayRef\|HashRef\)/,
b2b106d7 83'... (ArrayRef | HashRef) cannot accept code refs');
84
85is($HashOrArray->validate(50),
c47cf415 86'Validation failed for \'ArrayRef\' with value 50 and Validation failed for \'HashRef\' with value 50 in (ArrayRef|HashRef)',
b2b106d7 87'... (ArrayRef | HashRef) cannot accept Numbers');
88
c47cf415 89done_testing;