Commit | Line | Data |
eee1a213 |
1 | use strict; |
2 | use warnings; |
3 | |
a28e50e4 |
4 | use Test::More; |
53a4d826 |
5 | use Test::Exception; |
f91aacb6 |
6 | use Test::Fatal; |
eee1a213 |
7 | |
8 | use Moose::Meta::TypeConstraint; |
9 | use Moose::Util::TypeConstraints; |
10 | |
11 | |
12 | TODO: |
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 |
33 | lives_ok { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) } |
eee1a213 |
34 | 'Type names can contain periods and colons'; |
35 | |
53a4d826 |
36 | throws_ok { subtype 'Foo-Baz' => as 'Item' } |
eee1a213 |
37 | qr/contains invalid characters/, |
38 | 'Type names cannot contain a dash (via subtype sugar)'; |
39 | |
53a4d826 |
40 | lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' } |
eee1a213 |
41 | 'Type names can contain periods and colons (via subtype sugar)'; |
42 | |
43 | is( 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 | |
47 | is( 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 | |
51 | done_testing; |