Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 001_basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 14;
7 use Test::Deep;
8
9 BEGIN {
10     use_ok('MooseX::Storage');
11 }
12
13 {
14
15     package Foo;
16     use Moose;
17     use MooseX::Storage;
18
19     with Storage;
20
21     has 'number'  => ( is => 'ro', isa => 'Int' );
22     has 'string'  => ( is => 'ro', isa => 'Str' );
23     has 'boolean' => ( is => 'ro', isa => 'Bool' );
24     has 'float'   => ( is => 'ro', isa => 'Num' );
25     has 'array'   => ( is => 'ro', isa => 'ArrayRef' );
26     has 'hash'    => ( is => 'ro', isa => 'HashRef' );
27     has 'object'  => ( is => 'ro', isa => 'Foo' );
28     has 'union'   => ( is => 'ro', isa => 'ArrayRef|Str' );
29     has 'union2'   => ( is => 'ro', isa => 'ArrayRef|Str' );
30 }
31
32 {
33     my $foo = Foo->new(
34         number  => 10,
35         string  => 'foo',
36         boolean => 1,
37         float   => 10.5,
38         array   => [ 1 .. 10 ],
39         hash    => { map { $_ => undef } ( 1 .. 10 ) },
40         object  => Foo->new( number => 2 ),
41         union   => [ 1, 2, 3 ],
42         union2  => 'A String'
43     );
44     isa_ok( $foo, 'Foo' );
45
46     cmp_deeply(
47         $foo->pack,
48         {
49             __CLASS__ => 'Foo',
50             number    => 10,
51             string    => 'foo',
52             boolean   => 1,
53             float     => 10.5,
54             array     => [ 1 .. 10 ],
55             hash      => { map { $_ => undef } ( 1 .. 10 ) },
56             object    => {
57                             __CLASS__ => 'Foo',
58                             number    => 2
59                          },
60             union     => [ 1, 2, 3 ],
61             union2    => 'A String'
62         },
63         '... got the right frozen class'
64     );
65 }
66
67 {
68     my $foo = Foo->unpack(
69         {
70             __CLASS__ => 'Foo',
71             number    => 10,
72             string    => 'foo',
73             boolean   => 1,
74             float     => 10.5,
75             array     => [ 1 .. 10 ],
76             hash      => { map { $_ => undef } ( 1 .. 10 ) },
77             object    => {
78                             __CLASS__ => 'Foo',
79                             number    => 2
80                          },
81             union     => [ 1, 2, 3 ],
82             union2    => 'A String'
83         }
84     );
85     isa_ok( $foo, 'Foo' );
86
87     is( $foo->number, 10,    '... got the right number' );
88     is( $foo->string, 'foo', '... got the right string' );
89     ok( $foo->boolean,       '... got the right boolean' );
90     is( $foo->float,  10.5,  '... got the right float' );
91     cmp_deeply( $foo->array, [ 1 .. 10 ], '... got the right array' );
92     cmp_deeply(
93         $foo->hash,
94         { map { $_ => undef } ( 1 .. 10 ) },
95         '... got the right hash'
96     );
97
98     isa_ok( $foo->object, 'Foo' );
99     is( $foo->object->number, 2,
100         '... got the right number (in the embedded object)' );
101     cmp_deeply( $foo->union, [ 1 .. 3 ], '... got the right array (in the union)' );
102     is( $foo->union2,  'A String',  '... got the right string (in the union)' );
103 }