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