Revert autogenerated tests. Tests should not changed radically.
[gitmo/Mouse.git] / t / 040_type_constraints / failing / 014_type_notation_parser.t
diff --git a/t/040_type_constraints/failing/014_type_notation_parser.t b/t/040_type_constraints/failing/014_type_notation_parser.t
new file mode 100644 (file)
index 0000000..b2821c1
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 41;
+
+BEGIN {
+    use_ok("Mouse::Util::TypeConstraints");
+}
+
+=pod
+
+This is a good candidate for LectroTest
+Volunteers welcome :)
+
+=cut
+
+## check the containers
+
+ok(Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint($_),
+   '... this correctly detected a container (' . $_ . ')')
+    for (
+    'ArrayRef[Foo]',
+    'ArrayRef[Foo | Int]',
+    'ArrayRef[ArrayRef[Int]]',
+    'ArrayRef[ArrayRef[Int | Foo]]',
+    'ArrayRef[ArrayRef[Int|Str]]',
+);
+
+ok(!Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint($_),
+   '... this correctly detected a non-container (' . $_ . ')')
+    for (
+    'ArrayRef[]',
+    'ArrayRef[Foo]Bar',
+);
+
+{
+    my %split_tests = (
+        'ArrayRef[Foo]'                 => [ 'ArrayRef', 'Foo' ],
+        'ArrayRef[Foo | Int]'           => [ 'ArrayRef', 'Foo | Int' ],
+        'ArrayRef[Foo|Int]'             => [ 'ArrayRef', 'Foo|Int' ],
+        # these will get processed with recusion,
+        # so we only need to detect it once
+        'ArrayRef[ArrayRef[Int]]'       => [ 'ArrayRef', 'ArrayRef[Int]' ],
+        'ArrayRef[ArrayRef[Int | Foo]]' => [ 'ArrayRef', 'ArrayRef[Int | Foo]' ],
+        'ArrayRef[ArrayRef[Int|Str]]'   => [ 'ArrayRef', 'ArrayRef[Int|Str]' ],
+    );
+
+    is_deeply(
+        [ Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint($_) ],
+        $split_tests{$_},
+        '... this correctly split the container (' . $_ . ')'
+    ) for keys %split_tests;
+}
+
+## now for the unions
+
+ok(Mouse::Util::TypeConstraints::_detect_type_constraint_union($_),
+   '... this correctly detected union (' . $_ . ')')
+    for (
+    'Int | Str',
+    'Int|Str',
+    'ArrayRef[Foo] | Int',
+    'ArrayRef[Foo]|Int',
+    'Int | ArrayRef[Foo]',
+    'Int|ArrayRef[Foo]',
+    'ArrayRef[Foo | Int] | Str',
+    'ArrayRef[Foo|Int]|Str',
+    'Str | ArrayRef[Foo | Int]',
+    'Str|ArrayRef[Foo|Int]',
+    'Some|Silly|Name|With|Pipes | Int',
+    'Some|Silly|Name|With|Pipes|Int',
+);
+
+ok(!Mouse::Util::TypeConstraints::_detect_type_constraint_union($_),
+   '... this correctly detected a non-union (' . $_ . ')')
+    for (
+    'Int',
+    'ArrayRef[Foo | Int]',
+    'ArrayRef[Foo|Int]',
+);
+
+{
+    my %split_tests = (
+        'Int | Str'                        => [ 'Int', 'Str' ],
+        'Int|Str'                          => [ 'Int', 'Str' ],
+        'ArrayRef[Foo] | Int'              => [ 'ArrayRef[Foo]', 'Int' ],
+        'ArrayRef[Foo]|Int'                => [ 'ArrayRef[Foo]', 'Int' ],
+        'Int | ArrayRef[Foo]'              => [ 'Int', 'ArrayRef[Foo]' ],
+        'Int|ArrayRef[Foo]'                => [ 'Int', 'ArrayRef[Foo]' ],
+        'ArrayRef[Foo | Int] | Str'        => [ 'ArrayRef[Foo | Int]', 'Str' ],
+        'ArrayRef[Foo|Int]|Str'            => [ 'ArrayRef[Foo|Int]', 'Str' ],
+        'Str | ArrayRef[Foo | Int]'        => [ 'Str', 'ArrayRef[Foo | Int]' ],
+        'Str|ArrayRef[Foo|Int]'            => [ 'Str', 'ArrayRef[Foo|Int]' ],
+        'Some|Silly|Name|With|Pipes | Int' => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ],
+        'Some|Silly|Name|With|Pipes|Int'   => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ],
+    );
+
+    is_deeply(
+        [ Mouse::Util::TypeConstraints::_parse_type_constraint_union($_) ],
+        $split_tests{$_},
+        '... this correctly split the union (' . $_ . ')'
+    ) for keys %split_tests;
+}