X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F012_param_json.t;h=b855ef12a8f4598c785513b531db6ed6d904d6b9;hb=19d8a777247d4816be278da681de598526eaf1f2;hp=5ce5c24dc3a6cda8d6617b4abe23e74db6339de5;hpb=b5f363acfcf077778dd4f3b59460a0cbb9e51400;p=gitmo%2FMooseX-Storage.git diff --git a/t/012_param_json.t b/t/012_param_json.t index 5ce5c24..b855ef1 100644 --- a/t/012_param_json.t +++ b/t/012_param_json.t @@ -1,27 +1,24 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; +use Test::Deep; -BEGIN { - local $@; - plan skip_all => "MooseX::Storage::Format::JSONpm required for this test" - unless eval "require MooseX::Storage::Format::JSONpm; 1"; -} +use Test::Requires { + 'MooseX::Storage::Format::JSONpm' => 0.01, # skip all if not installed +}; -plan tests => 3; -use_ok('MooseX::Storage'); +BEGIN { + plan tests => 6; + use_ok('MooseX::Storage'); +} { - package Foo; use Moose; use MooseX::Storage; with Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ] ); - # with Storage(format => 'JSONpm'); has 'string' => ( is => 'ro', isa => 'Str' ); has 'float' => ( is => 'ro', isa => 'Num' ); @@ -44,3 +41,35 @@ use_ok('MooseX::Storage'); } +{ + package Bar; + use Moose; + use MooseX::Storage; + + our $VERSION = '0.01'; + + with 'MooseX::Storage::Deferred'; + + has 'x' => (is => 'rw', isa => 'Int'); + has 'y' => (is => 'rw', isa => 'Int'); +} + +for my $jsonpm ( + [ string => 'JSONpm' ], + [ aref0p => [ JSONpm => ] ], + [ aref1p => [ JSONpm => { json_opts => { pretty => 1 } } ] ], +) { + my ($name, $p) = @$jsonpm; + + my $json = eval { Bar->new(x => 10, y => 20)->freeze({ format => $p }) }; + + cmp_deeply( + JSON->new->decode($json), + { + '__CLASS__' => 'Bar-0.01', + x => 10, + y => 20, + }, + "correct deferred freeze from $name", + ); +}