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