adding in a utf8 test
[gitmo/MooseX-Storage.git] / t / 002_basic_io.t
CommitLineData
7aac8ce9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7
8{
9 package Foo;
10 use Moose;
11 use MooseX::Storage;
12
13 with Storage(
14 format => 'JSON',
15 io => 'File',
16 );
17
18 has 'number' => (is => 'ro', isa => 'Int');
19 has 'string' => (is => 'ro', isa => 'Str');
20 has 'float' => (is => 'ro', isa => 'Num');
21 has 'array' => (is => 'ro', isa => 'ArrayRef');
22 has 'hash' => (is => 'ro', isa => 'HashRef');
23 has 'object' => (is => 'ro', isa => 'Object');
24}
25
26my $file = 'temp.json';
27
28{
29 my $foo = Foo->new(
30 number => 10,
31 string => 'foo',
32 float => 10.5,
33 array => [ 1 .. 10 ],
34 hash => { map { $_ => undef } (1 .. 10) },
35 object => Foo->new( number => 2 ),
36 );
37 isa_ok($foo, 'Foo');
38
39 $foo->store($file);
40}
41
42{
43 my $foo = Foo->load($file);
44 isa_ok($foo, 'Foo');
45
46 is($foo->number, 10, '... got the right number');
47 is($foo->string, 'foo', '... got the right string');
48 is($foo->float, 10.5, '... got the right float');
49 is_deeply($foo->array, [ 1 .. 10], '... got the right array');
50 is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
51
52 isa_ok($foo->object, 'Foo');
53 is($foo->object->number, 2, '... got the right number (in the embedded object)');
54}
55
56unlink $file;