Commit | Line | Data |
f1917f58 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
f1917f58 |
7 | |
8 | BEGIN { |
9 | use_ok("Moose::Util::TypeConstraints"); |
10 | } |
11 | |
3796382a |
12 | =pod |
13 | |
6549b0d1 |
14 | This is a good candidate for LectroTest |
3796382a |
15 | Volunteers welcome :) |
16 | |
17 | =cut |
18 | |
f1917f58 |
19 | ## check the containers |
20 | |
d03bd989 |
21 | ok(Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), |
f1917f58 |
22 | '... this correctly detected a container (' . $_ . ')') |
23 | for ( |
24 | 'ArrayRef[Foo]', |
25 | 'ArrayRef[Foo | Int]', |
d03bd989 |
26 | 'ArrayRef[ArrayRef[Int]]', |
27 | 'ArrayRef[ArrayRef[Int | Foo]]', |
28 | 'ArrayRef[ArrayRef[Int|Str]]', |
f1917f58 |
29 | ); |
30 | |
d03bd989 |
31 | ok(!Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), |
f1917f58 |
32 | '... this correctly detected a non-container (' . $_ . ')') |
33 | for ( |
34 | 'ArrayRef[]', |
35 | 'ArrayRef[Foo]Bar', |
36 | ); |
37 | |
38 | { |
39 | my %split_tests = ( |
40 | 'ArrayRef[Foo]' => [ 'ArrayRef', 'Foo' ], |
41 | 'ArrayRef[Foo | Int]' => [ 'ArrayRef', 'Foo | Int' ], |
d03bd989 |
42 | 'ArrayRef[Foo|Int]' => [ 'ArrayRef', 'Foo|Int' ], |
43 | # these will get processed with recusion, |
f1917f58 |
44 | # so we only need to detect it once |
d03bd989 |
45 | 'ArrayRef[ArrayRef[Int]]' => [ 'ArrayRef', 'ArrayRef[Int]' ], |
f1917f58 |
46 | 'ArrayRef[ArrayRef[Int | Foo]]' => [ 'ArrayRef', 'ArrayRef[Int | Foo]' ], |
d03bd989 |
47 | 'ArrayRef[ArrayRef[Int|Str]]' => [ 'ArrayRef', 'ArrayRef[Int|Str]' ], |
f1917f58 |
48 | ); |
49 | |
50 | is_deeply( |
0fbd4b0a |
51 | [ Moose::Util::TypeConstraints::_parse_parameterized_type_constraint($_) ], |
f1917f58 |
52 | $split_tests{$_}, |
53 | '... this correctly split the container (' . $_ . ')' |
54 | ) for keys %split_tests; |
55 | } |
56 | |
57 | ## now for the unions |
58 | |
d03bd989 |
59 | ok(Moose::Util::TypeConstraints::_detect_type_constraint_union($_), |
f1917f58 |
60 | '... this correctly detected union (' . $_ . ')') |
61 | for ( |
62 | 'Int | Str', |
d03bd989 |
63 | 'Int|Str', |
f1917f58 |
64 | 'ArrayRef[Foo] | Int', |
d03bd989 |
65 | 'ArrayRef[Foo]|Int', |
f1917f58 |
66 | 'Int | ArrayRef[Foo]', |
d03bd989 |
67 | 'Int|ArrayRef[Foo]', |
f1917f58 |
68 | 'ArrayRef[Foo | Int] | Str', |
d03bd989 |
69 | 'ArrayRef[Foo|Int]|Str', |
70 | 'Str | ArrayRef[Foo | Int]', |
71 | 'Str|ArrayRef[Foo|Int]', |
72 | 'Some|Silly|Name|With|Pipes | Int', |
73 | 'Some|Silly|Name|With|Pipes|Int', |
f1917f58 |
74 | ); |
75 | |
d03bd989 |
76 | ok(!Moose::Util::TypeConstraints::_detect_type_constraint_union($_), |
f1917f58 |
77 | '... this correctly detected a non-union (' . $_ . ')') |
78 | for ( |
79 | 'Int', |
80 | 'ArrayRef[Foo | Int]', |
d03bd989 |
81 | 'ArrayRef[Foo|Int]', |
f1917f58 |
82 | ); |
83 | |
84 | { |
85 | my %split_tests = ( |
86 | 'Int | Str' => [ 'Int', 'Str' ], |
d03bd989 |
87 | 'Int|Str' => [ 'Int', 'Str' ], |
f1917f58 |
88 | 'ArrayRef[Foo] | Int' => [ 'ArrayRef[Foo]', 'Int' ], |
d03bd989 |
89 | 'ArrayRef[Foo]|Int' => [ 'ArrayRef[Foo]', 'Int' ], |
f1917f58 |
90 | 'Int | ArrayRef[Foo]' => [ 'Int', 'ArrayRef[Foo]' ], |
d03bd989 |
91 | 'Int|ArrayRef[Foo]' => [ 'Int', 'ArrayRef[Foo]' ], |
f1917f58 |
92 | 'ArrayRef[Foo | Int] | Str' => [ 'ArrayRef[Foo | Int]', 'Str' ], |
d03bd989 |
93 | 'ArrayRef[Foo|Int]|Str' => [ 'ArrayRef[Foo|Int]', 'Str' ], |
94 | 'Str | ArrayRef[Foo | Int]' => [ 'Str', 'ArrayRef[Foo | Int]' ], |
95 | 'Str|ArrayRef[Foo|Int]' => [ 'Str', 'ArrayRef[Foo|Int]' ], |
96 | 'Some|Silly|Name|With|Pipes | Int' => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ], |
97 | 'Some|Silly|Name|With|Pipes|Int' => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ], |
f1917f58 |
98 | ); |
99 | |
100 | is_deeply( |
101 | [ Moose::Util::TypeConstraints::_parse_type_constraint_union($_) ], |
102 | $split_tests{$_}, |
103 | '... this correctly split the union (' . $_ . ')' |
104 | ) for keys %split_tests; |
105 | } |
a28e50e4 |
106 | |
107 | done_testing; |