Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 020_basic_yaml_syck.t
CommitLineData
f16b5740 1#!/usr/bin/perl
2$|++;
3use strict;
4use warnings;
5
6use Test::More;
619ab942 7use Test::Deep;
f16b5740 8
0b173188 9use Test::Requires {
10 'YAML::Any' => 0.01, # skip all if not installed
11 'YAML::Syck' => 0.01,
12 'Test::Without::Module' => 0.01,
13};
14
f16b5740 15BEGIN {
f16b5740 16 Test::Without::Module->import(YAML::Any->order);
17 Test::Without::Module->unimport('YAML::Syck');
18 plan tests => 10;
19 use_ok('MooseX::Storage');
20}
21
22{
f16b5740 23 package Foo;
24 use Moose;
25 use MooseX::Storage;
26
27 with Storage( 'format' => 'YAML' );
28
29 has 'number' => ( is => 'ro', isa => 'Int' );
30 has 'string' => ( is => 'ro', isa => 'Str' );
31 has 'float' => ( is => 'ro', isa => 'Num' );
32 has 'array' => ( is => 'ro', isa => 'ArrayRef' );
33 has 'hash' => ( is => 'ro', isa => 'HashRef' );
34 has 'object' => ( is => 'ro', isa => 'Object' );
35}
36
37{
38 my $foo = Foo->new(
39 number => 10,
40 string => 'foo',
41 float => 10.5,
42 array => [ 1 .. 10 ],
43 hash => { map { $_ => undef } ( 1 .. 10 ) },
44 object => Foo->new( number => 2 ),
45 );
46 isa_ok( $foo, 'Foo' );
47
48 my $yaml = $foo->freeze;
49
50 my $bar = Foo->thaw( $yaml );
51 isa_ok( $bar, 'Foo' );
52
53 is( $bar->number, 10, '... got the right number' );
54 is( $bar->string, 'foo', '... got the right string' );
55 is( $bar->float, 10.5, '... got the right float' );
619ab942 56 cmp_deeply( $bar->array, [ 1 .. 10 ], '... got the right array' );
57 cmp_deeply(
f16b5740 58 $bar->hash,
59 { map { $_ => undef } ( 1 .. 10 ) },
60 '... got the right hash'
61 );
62
63 isa_ok( $bar->object, 'Foo' );
64 is( $bar->object->number, 2,
65 '... got the right number (in the embedded object)' );
66}
67