+#!perl
+
+# XXX:
+# XXX: !!!Currently this test is not compatible with Moose!!!
+# XXX:
+
use strict;
use warnings;
-use Test::More tests => 18;
+use Test::More tests => 22;
{
package Foo;
eval {
Foo->new( bar => +{} );
};
-like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Baz\|Str\|Undef' failed with value HASH\(\w+\)/, 'type constraint and coercion failed')
+like($@, qr/^Attribute \(bar\) does not pass the type constraint because: Validation failed for 'Baz\|Str\|Undef' with value HASH\(\w+\)/, 'type constraint and coercion failed')
or diag "\$@='$@'";
eval {
}
eval { Funk->new( foo => 'aaa' ) };
-like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'KLASS\|Type3\|Undef' failed with value aaa/;
+like $@, qr/Attribute \(foo\) does not pass the type constraint because: Validation failed for 'KLASS\|Type3\|Undef' with value aaa/;
my $k = Funk->new;
ok $k, 'got an object 4';
$k->foo(undef);
is $k->foo, undef, 'foo is undef';
+# or-combination operator ('|')
+{
+ use Mouse::Util::TypeConstraints;
+ my $Int = find_type_constraint 'Int';
+ my $Str = find_type_constraint 'Str';
+ my $Object = find_type_constraint 'Object';
+
+ *t = \&Mouse::Util::TypeConstraints::find_or_parse_type_constraint; # alias
+
+ is $Int | $Str, t('Int | Str');
+ is $Str | $Int, t('Int | Str');
+
+ is $Int | $Str | $Object, t('Int | Str | Object');
+ is $Str | $Object | $Int, t('Int | Str | Object');
+}
+