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