Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 002_basic_io.t
CommitLineData
7aac8ce9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
4fa64e86 6use Test::More;
619ab942 7use Test::Deep;
08d0f48e 8use File::Temp qw(tempdir);
cfd008fa 9
5e5d4e28 10use File::Spec::Functions;
cfd008fa 11
12my $dir = tempdir;
4fa64e86 13
0b173188 14use Test::Requires {
15 'JSON::Any' => 0.01, # skip all if not installed
16};
17
18BEGIN {
4fa64e86 19 plan tests => 10;
20 use_ok('MooseX::Storage');
21}
7aac8ce9 22
23{
24 package Foo;
25 use Moose;
26 use MooseX::Storage;
b5f363ac 27
7aac8ce9 28 with Storage(
29 format => 'JSON',
30 io => 'File',
31 );
b5f363ac 32
7aac8ce9 33 has 'number' => (is => 'ro', isa => 'Int');
34 has 'string' => (is => 'ro', isa => 'Str');
b5f363ac 35 has 'float' => (is => 'ro', isa => 'Num');
7aac8ce9 36 has 'array' => (is => 'ro', isa => 'ArrayRef');
b5f363ac 37 has 'hash' => (is => 'ro', isa => 'HashRef');
38 has 'object' => (is => 'ro', isa => 'Object');
7aac8ce9 39}
40
5e5d4e28 41my $file = catfile($dir, 'temp.json');
7aac8ce9 42
43{
44 my $foo = Foo->new(
45 number => 10,
46 string => 'foo',
47 float => 10.5,
48 array => [ 1 .. 10 ],
49 hash => { map { $_ => undef } (1 .. 10) },
50 object => Foo->new( number => 2 ),
51 );
52 isa_ok($foo, 'Foo');
53
54 $foo->store($file);
55}
56
57{
58 my $foo = Foo->load($file);
59 isa_ok($foo, 'Foo');
60
61 is($foo->number, 10, '... got the right number');
62 is($foo->string, 'foo', '... got the right string');
63 is($foo->float, 10.5, '... got the right float');
619ab942 64 cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
65 cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
7aac8ce9 66
67 isa_ok($foo->object, 'Foo');
68 is($foo->object->number, 2, '... got the right number (in the embedded object)');
69}
70