Regenerate test files
[gitmo/Mouse.git] / t / 200_examples / 005_example_w_TestDeep.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10
11 =pod
12
13 This tests how well Mouse type constraints
14 play with Test::Deep.
15
16 Its not as pretty as Declare::Constraints::Simple,
17 but it is not completely horrid either.
18
19 =cut
20
21 use Test::Requires {
22     'Test::Deep' => '0.01', # skip all if not installed
23 };
24
25 use Test::Exception;
26
27 {
28     package Foo;
29     use Mouse;
30     use Mouse::Util::TypeConstraints;
31
32     use Test::Deep qw[
33         eq_deeply array_each subhashof ignore
34     ];
35
36     # define your own type ...
37     type 'ArrayOfHashOfBarsAndRandomNumbers'
38         => where {
39             eq_deeply($_,
40                 array_each(
41                     subhashof({
42                         bar           => Test::Deep::isa('Bar'),
43                         random_number => ignore()
44                     })
45                 )
46             )
47         };
48
49     has 'bar' => (
50         is  => 'rw',
51         isa => 'ArrayOfHashOfBarsAndRandomNumbers',
52     );
53
54     package Bar;
55     use Mouse;
56 }
57
58 my $array_of_hashes = [
59     { bar => Bar->new, random_number => 10 },
60     { bar => Bar->new },
61 ];
62
63 my $foo;
64 lives_ok {
65     $foo = Foo->new('bar' => $array_of_hashes);
66 } '... construction succeeded';
67 isa_ok($foo, 'Foo');
68
69 is_deeply($foo->bar, $array_of_hashes, '... got our value correctly');
70
71 dies_ok {
72     $foo->bar({});
73 } '... validation failed correctly';
74
75 dies_ok {
76     $foo->bar([{ foo => 3 }]);
77 } '... validation failed correctly';
78
79 done_testing;