Standardize use of Test::Exception before converting to Test::Fatal
[gitmo/Moose.git] / t / 040_type_constraints / 033_type_names.t
CommitLineData
eee1a213 1use strict;
2use warnings;
3
a28e50e4 4use Test::More;
53a4d826 5use Test::Exception;
f91aacb6 6use Test::Fatal;
eee1a213 7
8use Moose::Meta::TypeConstraint;
9use Moose::Util::TypeConstraints;
10
11
12TODO:
13{
14 local $TODO = 'type names are not validated in the TC metaclass';
15
4d1b85c1 16 # Test written in this way to avoid a warning from like(undef, qr...);
17 # -- rjbs, 2010-10-25
18 my $error = exception {
19 Moose::Meta::TypeConstraint->new( name => 'Foo-Bar' )
20 };
21
22 if (defined $error) {
23 like(
24 $error,
25 qr/contains invalid characters/,
26 'Type names cannot contain a dash',
27 );
28 } else {
29 fail("Type names cannot contain a dash");
30 }
eee1a213 31}
32
53a4d826 33lives_ok { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }
eee1a213 34'Type names can contain periods and colons';
35
53a4d826 36throws_ok { subtype 'Foo-Baz' => as 'Item' }
eee1a213 37qr/contains invalid characters/,
38 'Type names cannot contain a dash (via subtype sugar)';
39
53a4d826 40lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' }
eee1a213 41'Type names can contain periods and colons (via subtype sugar)';
42
43is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'),
44 undef,
45 'find_or_parse_type_constraint returns undef on an invalid name' );
46
47is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Va.lid]'),
48 'ArrayRef[Va.lid]',
49 'find_or_parse_type_constraint returns name for valid name' );
a28e50e4 50
51done_testing;