use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 35;
use Test::Exception;
BEGIN {
ok($Str_or_Undef->check(undef), '... (Str | Undef) can accept an Undef value');
ok($Str_or_Undef->check('String'), '... (Str | Undef) can accept a String value');
+ok($Str_or_Undef->is_a_type_of($Str), "subtype of Str");
+ok($Str_or_Undef->is_a_type_of($Undef), "subtype of Undef");
+
+ok( !$Str_or_Undef->equals($Str), "not equal to Str" );
+ok( $Str_or_Undef->equals($Str_or_Undef), "equal to self" );
+ok( $Str_or_Undef->equals(Moose::Meta::TypeConstraint::Union->new(type_constraints => [ $Str, $Undef ])), "equal to clone" );
+ok( $Str_or_Undef->equals(Moose::Meta::TypeConstraint::Union->new(type_constraints => [ $Undef, $Str ])), "equal to reversed clone" );
+
+ok( !$Str_or_Undef->is_a_type_of("ThisTypeDoesNotExist"), "not type of non existant type" );
+ok( !$Str_or_Undef->is_subtype_of("ThisTypeDoesNotExist"), "not subtype of non existant type" );
+
# another ....
my $ArrayRef = find_type_constraint('ArrayRef');
ok(!defined($HashOrArray->validate({})), '... (ArrayRef | HashRef) can accept {}');
like($HashOrArray->validate(\(my $var2)),
-qr/Validation failed for \'ArrayRef\' failed with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' failed with value SCALAR\(0x.+?\) in \(ArrayRef \| HashRef\)/,
+qr/Validation failed for \'ArrayRef\' failed with value SCALAR\(0x.+?\) and Validation failed for \'HashRef\' failed with value SCALAR\(0x.+?\) in \(ArrayRef\|HashRef\)/,
'... (ArrayRef | HashRef) cannot accept scalar refs');
like($HashOrArray->validate(sub {}),
-qr/Validation failed for \'ArrayRef\' failed with value CODE\(0x.+?\) and Validation failed for \'HashRef\' failed with value CODE\(0x.+?\) in \(ArrayRef \| HashRef\)/,
+qr/Validation failed for \'ArrayRef\' failed with value CODE\(0x.+?\) and Validation failed for \'HashRef\' failed with value CODE\(0x.+?\) in \(ArrayRef\|HashRef\)/,
'... (ArrayRef | HashRef) cannot accept code refs');
is($HashOrArray->validate(50),
-'Validation failed for \'ArrayRef\' failed with value 50 and Validation failed for \'HashRef\' failed with value 50 in (ArrayRef | HashRef)',
+'Validation failed for \'ArrayRef\' failed with value 50 and Validation failed for \'HashRef\' failed with value 50 in (ArrayRef|HashRef)',
'... (ArrayRef | HashRef) cannot accept Numbers');
-my $StrOrArray = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Str, $ArrayRef]);
-isa_ok($StrOrArray, 'Moose::Meta::TypeConstraint');
-
-ok(!defined($StrOrArray->validate("hi")));
-ok(!defined($StrOrArray->validate([])));
-ok(!defined($StrOrArray->validate([1])));
-
-like($StrOrArray->validate({}),
-qr/Validation failed for \'Str\' failed with value HASH\(0x.+?\) and Validation failed for \'ArrayRef\' failed with value HASH\(0x.+?\) in \(Str \| ArrayRef\)/,
-'... (Str | ArrayRef) cannot accept HashRefs');
-
-ok($Str->is_subtype_of($StrOrArray), "Str is a subtype of (Str | ArrayRef)");
-ok($ArrayRef->is_subtype_of($StrOrArray), "ArrayRef is a subtype of (Str | ArrayRef)" );
-