use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More;
use Test::Exception;
+use Scalar::Util qw(refaddr);
BEGIN {
- use_ok('Moose::Util::TypeConstraints');
+ use_ok('Moose::Util::TypeConstraints');
}
# subtype 'aliasing' ...
my $subtype2 = subtype 'New2' => as $subtype1;
ok $subtype2 => 'made a subtype of our subtype';
+
+# assert_valid
+
+{
+ my $type = find_type_constraint('Num');
+
+ my $ok_1 = eval { $type->assert_valid(1); };
+ ok($ok_1, "we can assert_valid that 1 is of type $type");
+
+ my $ok_2 = eval { $type->assert_valid('foo'); };
+ my $error = $@;
+ ok(! $ok_2, "'foo' is not of type $type");
+ like(
+ $error,
+ qr{validation failed for .\Q$type\E.}i,
+ "correct error thrown"
+ );
+}
+
+{
+ for my $t (qw(Bar Foo)) {
+ my $tc = Moose::Meta::TypeConstraint->new({
+ name => $t,
+ });
+
+ Moose::Util::TypeConstraints::register_type_constraint($tc);
+ }
+
+ my $foo = Moose::Util::TypeConstraints::find_type_constraint('Foo');
+ my $bar = Moose::Util::TypeConstraints::find_type_constraint('Bar');
+
+ ok(!$foo->equals($bar), "Foo type is not equal to Bar type");
+ ok( $foo->equals($foo), "Foo equals Foo");
+ ok( 0+$foo == refaddr($foo), "overloading works");
+}
+
+ok $subtype1, "type constraint boolean overload works";
+
+done_testing;