this is a shorter way of specifying the gitmo repository properly
[gitmo/MooseX-Storage.git] / t / 020_basic_yaml.t
1 $|++;
2 use strict;
3 use warnings;
4
5 use Test::More;
6 use Test::Deep;
7
8 use Test::Requires {
9     'YAML::Any' => 0.01, # skip all if not installed
10     'YAML'      => 0.01,
11     'Test::Without::Module' => 0.01,
12 };
13
14 BEGIN {
15     Test::Without::Module->import(YAML::Any->order);
16     Test::Without::Module->unimport('YAML');
17     plan tests => 10;
18     use_ok('MooseX::Storage');
19 }
20
21 {
22
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' );
56     cmp_deeply( $bar->array, [ 1 .. 10 ], '... got the right array' );
57     cmp_deeply(
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