Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 012_param_json.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Deep;
8
9 use Test::Requires {
10     'MooseX::Storage::Format::JSONpm' => 0.01, # skip all if not installed
11 };
12
13 BEGIN {
14     plan tests => 6;
15     use_ok('MooseX::Storage');
16 }
17
18 {
19     package Foo;
20     use Moose;
21     use MooseX::Storage;
22
23     with Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ] );
24
25     has 'string' => ( is => 'ro', isa => 'Str' );
26     has 'float'  => ( is => 'ro', isa => 'Num' );
27 }
28
29 {
30     my $foo = Foo->new(
31         string => 'foo',
32         float  => 10.5,
33     );
34     isa_ok( $foo, 'Foo' );
35
36     my $json = $foo->freeze;
37
38     isnt(
39         index($json, "\n"),
40         -1,
41         "there are newlines in our JSON, because it is pretty",
42     ) or diag $json;
43
44 }
45
46 {
47     package Bar;
48     use Moose;
49     use MooseX::Storage;
50
51     our $VERSION = '0.01';
52
53     with 'MooseX::Storage::Deferred';
54
55     has 'x' => (is => 'rw', isa => 'Int');
56     has 'y' => (is => 'rw', isa => 'Int');
57 }
58
59 for my $jsonpm (
60   [ string => 'JSONpm' ],
61   [ aref0p => [ JSONpm => ] ],
62   [ aref1p => [ JSONpm => { json_opts => { pretty => 1 } } ] ],
63 ) {
64     my ($name, $p) = @$jsonpm;
65
66     my $json = eval { Bar->new(x => 10, y => 20)->freeze({ format => $p }) };
67
68     cmp_deeply(
69         JSON->new->decode($json),
70         {
71             '__CLASS__' => 'Bar-0.01',
72             x => 10,
73             y => 20,
74         },
75         "correct deferred freeze from $name",
76     );
77 }