remove useless shebangs in tests
[gitmo/MooseX-Storage.git] / t / 002_basic_io.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Deep;
6 use File::Temp qw(tempdir);
7
8 use File::Spec::Functions;
9
10 my $dir = tempdir;
11
12 use Test::Requires {
13     'JSON::Any' => 0.01, # skip all if not installed
14 };
15
16 BEGIN {
17     plan tests => 10;
18     use_ok('MooseX::Storage');
19 }
20
21 {
22     package Foo;
23     use Moose;
24     use MooseX::Storage;
25     
26     with Storage(
27         format => 'JSON',
28         io     => 'File',
29     );
30     
31     has 'number' => (is => 'ro', isa => 'Int');
32     has 'string' => (is => 'ro', isa => 'Str');
33     has 'float'  => (is => 'ro', isa => 'Num');        
34     has 'array'  => (is => 'ro', isa => 'ArrayRef');
35     has 'hash'   => (is => 'ro', isa => 'HashRef');    
36         has 'object' => (is => 'ro', isa => 'Object');    
37 }
38
39 my $file = catfile($dir, 'temp.json');
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');
62     cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
63     cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
64
65     isa_ok($foo->object, 'Foo');
66     is($foo->object->number, 2, '... got the right number (in the embedded object)');
67 }
68