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