Run author side tests always
[gitmo/MooseX-Storage.git] / t / 100_io.t
CommitLineData
ec9c1923 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
4fa64e86 6use Test::More;
cfd008fa 7use Test::TempDir;
5e5d4e28 8use File::Spec::Functions;
cfd008fa 9my $dir = tempdir;
ec9c1923 10
766ab81f 11BEGIN {
4fa64e86 12 eval "use JSON::Any";
766ab81f 13 plan skip_all => "JSON::Any is required for this test" if $@;
14 plan tests => 10;
ec9c1923 15 use_ok('MooseX::Storage');
16}
17
18{
19 package Foo;
20 use Moose;
21 use MooseX::Storage;
766ab81f 22
ec9c1923 23 with Storage(format => 'JSON', io => 'File');
766ab81f 24
ec9c1923 25 has 'number' => (is => 'ro', isa => 'Int');
26 has 'string' => (is => 'ro', isa => 'Str');
766ab81f 27 has 'float' => (is => 'ro', isa => 'Num');
ec9c1923 28 has 'array' => (is => 'ro', isa => 'ArrayRef');
766ab81f 29 has 'hash' => (is => 'ro', isa => 'HashRef');
30 has 'object' => (is => 'ro', isa => 'Object');
ec9c1923 31}
32
5e5d4e28 33my $file = catfile( $dir, 'temp.json' );
ec9c1923 34
35{
36 my $foo = Foo->new(
37 number => 10,
38 string => 'foo',
39 float => 10.5,
40 array => [ 1 .. 10 ],
41 hash => { map { $_ => undef } (1 .. 10) },
42 object => Foo->new( number => 2 ),
43 );
44 isa_ok($foo, 'Foo');
45
46 $foo->store($file);
47}
48
49{
50 my $foo = Foo->load($file);
51 isa_ok($foo, 'Foo');
52
53 is($foo->number, 10, '... got the right number');
54 is($foo->string, 'foo', '... got the right string');
55 is($foo->float, 10.5, '... got the right float');
56 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
57 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
58
59 isa_ok($foo->object, 'Foo');
60 is($foo->object->number, 2, '... got the right number (in the embedded object)');
61}
62