Commit | Line | Data |
eee1a213 |
1 | use strict; |
2 | use warnings; |
3 | |
a28e50e4 |
4 | use Test::More; |
f91aacb6 |
5 | use Test::Fatal; |
eee1a213 |
6 | |
7 | use Moose::Meta::TypeConstraint; |
8 | use Moose::Util::TypeConstraints; |
9 | |
10 | |
11 | TODO: |
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 | |
b10dde3a |
32 | is( exception { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }, undef, 'Type names can contain periods and colons' ); |
eee1a213 |
33 | |
b10dde3a |
34 | like( exception { subtype 'Foo-Baz' => as 'Item' }, qr/contains invalid characters/, 'Type names cannot contain a dash (via subtype sugar)' ); |
eee1a213 |
35 | |
b10dde3a |
36 | is( exception { subtype 'Foo.Bar::Baz' => as 'Item' }, undef, 'Type names can contain periods and colons (via subtype sugar)' ); |
eee1a213 |
37 | |
38 | is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'), |
39 | undef, |
40 | 'find_or_parse_type_constraint returns undef on an invalid name' ); |
41 | |
42 | is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Va.lid]'), |
43 | 'ArrayRef[Va.lid]', |
44 | 'find_or_parse_type_constraint returns name for valid name' ); |
a28e50e4 |
45 | |
46 | done_testing; |