s/container/parameterized/
[gitmo/Moose.git] / t / 040_type_constraints / 014_type_notation_parser.t
CommitLineData
f1917f58 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 26;
7
8BEGIN {
9 use_ok("Moose::Util::TypeConstraints");
10}
11
12## check the containers
13
0fbd4b0a 14ok(Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_),
f1917f58 15 '... this correctly detected a container (' . $_ . ')')
16 for (
17 'ArrayRef[Foo]',
18 'ArrayRef[Foo | Int]',
19 'ArrayRef[ArrayRef[Int]]',
20 'ArrayRef[ArrayRef[Int | Foo]]',
21);
22
0fbd4b0a 23ok(!Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_),
f1917f58 24 '... this correctly detected a non-container (' . $_ . ')')
25 for (
26 'ArrayRef[]',
27 'ArrayRef[Foo]Bar',
28);
29
30{
31 my %split_tests = (
32 'ArrayRef[Foo]' => [ 'ArrayRef', 'Foo' ],
33 'ArrayRef[Foo | Int]' => [ 'ArrayRef', 'Foo | Int' ],
34 # these will get processed with recusion,
35 # so we only need to detect it once
36 'ArrayRef[ArrayRef[Int]]' => [ 'ArrayRef', 'ArrayRef[Int]' ],
37 'ArrayRef[ArrayRef[Int | Foo]]' => [ 'ArrayRef', 'ArrayRef[Int | Foo]' ],
38 );
39
40 is_deeply(
0fbd4b0a 41 [ Moose::Util::TypeConstraints::_parse_parameterized_type_constraint($_) ],
f1917f58 42 $split_tests{$_},
43 '... this correctly split the container (' . $_ . ')'
44 ) for keys %split_tests;
45}
46
47## now for the unions
48
49ok(Moose::Util::TypeConstraints::_detect_type_constraint_union($_),
50 '... this correctly detected union (' . $_ . ')')
51 for (
52 'Int | Str',
53 'ArrayRef[Foo] | Int',
54 'Int | ArrayRef[Foo]',
55 'ArrayRef[Foo | Int] | Str',
56 'Str | ArrayRef[Foo | Int]',
57 'Some|Silly|Name|With|Pipes | Int',
58);
59
60ok(!Moose::Util::TypeConstraints::_detect_type_constraint_union($_),
61 '... this correctly detected a non-union (' . $_ . ')')
62 for (
63 'Int',
64 'ArrayRef[Foo | Int]',
65 'Some|Silly|Name|With|Pipes',
66);
67
68{
69 my %split_tests = (
70 'Int | Str' => [ 'Int', 'Str' ],
71 'ArrayRef[Foo] | Int' => [ 'ArrayRef[Foo]', 'Int' ],
72 'Int | ArrayRef[Foo]' => [ 'Int', 'ArrayRef[Foo]' ],
73 'ArrayRef[Foo | Int] | Str' => [ 'ArrayRef[Foo | Int]', 'Str' ],
74 'Str | ArrayRef[Foo | Int]' => [ 'Str', 'ArrayRef[Foo | Int]' ],
75 'Some|Silly|Name|With|Pipes | Int' => [ 'Some|Silly|Name|With|Pipes', 'Int' ],
76 );
77
78 is_deeply(
79 [ Moose::Util::TypeConstraints::_parse_type_constraint_union($_) ],
80 $split_tests{$_},
81 '... this correctly split the union (' . $_ . ')'
82 ) for keys %split_tests;
83}