Add assert_valid() to Meta::TypeConstraint
[gitmo/Mouse.git] / t / 040_type_constraints / failing / 033_type_names.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 6;
5 use Test::Exception;
6
7 use Mouse::Meta::TypeConstraint;
8 use Mouse::Util::TypeConstraints;
9
10
11 TODO:
12 {
13     local $TODO = 'type names are not validated in the TC metaclass';
14
15     throws_ok { Mouse::Meta::TypeConstraint->new( name => 'Foo-Bar' ) }
16     qr/contains invalid characters/,
17         'Type names cannot contain a dash';
18 }
19
20 lives_ok { Mouse::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }
21 'Type names can contain periods and colons';
22
23 throws_ok { subtype 'Foo-Baz' => as 'Item' }
24 qr/contains invalid characters/,
25     'Type names cannot contain a dash (via subtype sugar)';
26
27 lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' }
28 'Type names can contain periods and colons (via subtype sugar)';
29
30 is( Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'),
31     undef,
32     'find_or_parse_type_constraint returns undef on an invalid name' );
33
34 is( Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Va.lid]'),
35     'ArrayRef[Va.lid]',
36     'find_or_parse_type_constraint returns name for valid name' );