Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 003_basic_w_embedded_objects.t
CommitLineData
913d96dd 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
8d8356bb 6use Test::More tests => 47;
619ab942 7use Test::Deep;
913d96dd 8
9BEGIN {
10 use_ok('MooseX::Storage');
11}
12
95f31c36 13=pod
14
b5f363ac 15This test checks the single level
16expansion and collpasing of the
95f31c36 17ArrayRef and HashRef type handlers.
18
19=cut
20
913d96dd 21{
22 package Bar;
23 use Moose;
24 use MooseX::Storage;
25
26 with Storage;
b5f363ac 27
95f31c36 28 has 'number' => (is => 'ro', isa => 'Int');
b5f363ac 29
913d96dd 30 package Foo;
31 use Moose;
32 use MooseX::Storage;
33
b5f363ac 34 with Storage;
913d96dd 35
b5f363ac 36 has 'bars' => (
37 is => 'ro',
38 isa => 'ArrayRef'
913d96dd 39 );
b5f363ac 40
95f31c36 41 package Baz;
42 use Moose;
43 use MooseX::Storage;
44
b5f363ac 45 with Storage;
95f31c36 46
b5f363ac 47 has 'bars' => (
48 is => 'ro',
49 isa => 'HashRef'
50 );
913d96dd 51}
52
53{
54 my $foo = Foo->new(
95f31c36 55 bars => [ map { Bar->new(number => $_) } (1 .. 10) ]
913d96dd 56 );
57 isa_ok( $foo, 'Foo' );
b5f363ac 58
619ab942 59 cmp_deeply(
913d96dd 60 $foo->pack,
61 {
ba5bba75 62 __CLASS__ => 'Foo',
b5f363ac 63 bars => [
913d96dd 64 map {
65 {
ba5bba75 66 __CLASS__ => 'Bar',
95f31c36 67 number => $_,
b5f363ac 68 }
913d96dd 69 } (1 .. 10)
b5f363ac 70 ],
913d96dd 71 },
72 '... got the right frozen class'
73 );
74}
75
76{
77 my $foo = Foo->unpack(
78 {
ba5bba75 79 __CLASS__ => 'Foo',
b5f363ac 80 bars => [
913d96dd 81 map {
82 {
ba5bba75 83 __CLASS__ => 'Bar',
95f31c36 84 number => $_,
b5f363ac 85 }
913d96dd 86 } (1 .. 10)
b5f363ac 87 ],
88 }
913d96dd 89 );
90 isa_ok( $foo, 'Foo' );
91
92 foreach my $i (1 .. scalar @{$foo->bars}) {
93 isa_ok($foo->bars->[$i - 1], 'Bar');
95f31c36 94 is($foo->bars->[$i - 1]->number, $i, "... got the right number ($i) in the Bar in Foo");
95 }
96}
97
98
99{
100 my $baz = Baz->new(
101 bars => { map { ($_ => Bar->new(number => $_)) } (1 .. 10) }
102 );
103 isa_ok( $baz, 'Baz' );
b5f363ac 104
619ab942 105 cmp_deeply(
95f31c36 106 $baz->pack,
107 {
ba5bba75 108 __CLASS__ => 'Baz',
95f31c36 109 bars => {
110 map {
111 ($_ => {
ba5bba75 112 __CLASS__ => 'Bar',
95f31c36 113 number => $_,
b5f363ac 114 })
95f31c36 115 } (1 .. 10)
b5f363ac 116 },
95f31c36 117 },
118 '... got the right frozen class'
119 );
120}
121
122{
123 my $baz = Baz->unpack(
124 {
ba5bba75 125 __CLASS__ => 'Baz',
95f31c36 126 bars => {
127 map {
128 ($_ => {
ba5bba75 129 __CLASS__ => 'Bar',
95f31c36 130 number => $_,
b5f363ac 131 })
95f31c36 132 } (1 .. 10)
b5f363ac 133 },
134 }
95f31c36 135 );
136 isa_ok( $baz, 'Baz' );
137
138 foreach my $k (keys %{$baz->bars}) {
139 isa_ok($baz->bars->{$k}, 'Bar');
140 is($baz->bars->{$k}->number, $k, "... got the right number ($k) in the Bar in Baz");
913d96dd 141 }
142}