support for recursive types, documentation and tests for that, random documentation...
[gitmo/MooseX-Types.git] / t / 15_recursion.t
CommitLineData
e7d06577 1## Test case inspired by Stevan Little
2
3BEGIN {
4 package MooseX::Types::Test::Recursion;
5
6 use Moose;
7
8 use Moose::Util::TypeConstraints;
9 use MooseX::Types::Moose qw(Str HashRef);
10 use MooseX::Types -declare => [qw(
11 RecursiveHashRef
12 )];
13
14 ## Define a recursive subtype and Cthulhu save us.
15 subtype RecursiveHashRef()
16 => as HashRef[Str() | RecursiveHashRef()];
17}
18
19{
20 package MooseX::Types::Test::Recursion::TestRunner;
21
22 BEGIN {
077ac262 23 use Test::More tests=>5;
24 use Test::Exception;
e7d06577 25
077ac262 26 ## Grab the newly created test type constraint
e7d06577 27 MooseX::Types::Test::Recursion->import(':all');
28 };
29
30
31 ok RecursiveHashRef->check({key=>"value"})
32 => 'properly validated {key=>"value"}';
33
34 ok RecursiveHashRef->check({key=>{subkey=>"value"}})
35 => 'properly validated {key=>{subkey=>"value"}}';
36
077ac262 37 ok RecursiveHashRef->check({
38 key=>{
39 subkey=>"value",
40 subkey2=>{
41 ssubkey1=>"value3",
42 ssubkey2=>"value4"
43 }
44 }
45 }) => 'properly validated deeper recursive values';
46
47 ok ! RecursiveHashRef->check({key=>[1,2,3]})
48 => 'Properly invalidates bad value';
e7d06577 49
077ac262 50 ok ! RecursiveHashRef->check({key=>{subkey=>"value",subkey2=>{ssubkey=>[1,2,3]}}})
51 => 'Properly invalidates bad value deeply';
e7d06577 52}
53
54
55
56
57
58