From: Tomas Doran Date: Tue, 10 Nov 2009 10:06:15 +0000 (+0000) Subject: Revert "Whitespace trim tests", this was clearly retarded of X-Git-Tag: 0.23~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5f363acfcf077778dd4f3b59460a0cbb9e51400;p=gitmo%2FMooseX-Storage.git Revert "Whitespace trim tests", this was clearly retarded of me as it breaks the YAML valid test (YAML being like that and all) which I can't run as Test::YAML::Valid in turn fails it's tests so I can't install it. This reverts commit 766ab81f59db9f3087e0011112ff2e69133a85c5. --- diff --git a/t/001_basic.t b/t/001_basic.t index d3c60f1..fcb591a 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -37,7 +37,7 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { @@ -48,10 +48,10 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, + object => { + __CLASS__ => 'Foo', + number => 2 + }, }, '... got the right frozen class' ); @@ -67,11 +67,11 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, - } + object => { + __CLASS__ => 'Foo', + number => 2 + }, + } ); isa_ok( $foo, 'Foo' ); diff --git a/t/002_basic_io.t b/t/002_basic_io.t index d994cdd..06a3322 100644 --- a/t/002_basic_io.t +++ b/t/002_basic_io.t @@ -10,9 +10,9 @@ use File::Spec::Functions; my $dir = tempdir; -BEGIN { +BEGIN { eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; + plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 10; use_ok('MooseX::Storage'); } @@ -21,18 +21,18 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with Storage( format => 'JSON', io => 'File', ); - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'ro', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); } my $file = catfile($dir, 'temp.json'); diff --git a/t/002_basic_w_subtypes.t b/t/002_basic_w_subtypes.t index dedec18..16bad20 100644 --- a/t/002_basic_w_subtypes.t +++ b/t/002_basic_w_subtypes.t @@ -11,8 +11,8 @@ BEGIN { =pod -This extends the 001_basic test to -show that subtypes will DWIM in most +This extends the 001_basic test to +show that subtypes will DWIM in most cases. =cut @@ -26,25 +26,25 @@ cases. use Scalar::Util 'looks_like_number'; - with Storage; - - subtype 'Natural' + with Storage; + + subtype 'Natural' => as 'Int' => where { $_ > 0 }; - - subtype 'HalfNum' + + subtype 'HalfNum' => as 'Num' - => where { "$_" =~ /\.5$/ }; - + => where { "$_" =~ /\.5$/ }; + subtype 'FooString' => as 'Str' => where { lc($_) eq 'foo' }; - - subtype 'IntArray' + + subtype 'IntArray' => as 'ArrayRef' => where { scalar grep { looks_like_number($_) } @{$_} }; - subtype 'UndefHash' + subtype 'UndefHash' => as 'HashRef' => where { scalar grep { !defined($_) } values %{$_} }; @@ -66,7 +66,7 @@ cases. object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { @@ -76,10 +76,10 @@ cases. float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, + object => { + __CLASS__ => 'Foo', + number => 2 + }, }, '... got the right frozen class' ); @@ -94,11 +94,11 @@ cases. float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, - } + object => { + __CLASS__ => 'Foo', + number => 2 + }, + } ); isa_ok( $foo, 'Foo' ); diff --git a/t/003_basic_w_embedded_objects.t b/t/003_basic_w_embedded_objects.t index 19d3edb..55c4e6c 100644 --- a/t/003_basic_w_embedded_objects.t +++ b/t/003_basic_w_embedded_objects.t @@ -11,8 +11,8 @@ BEGIN { =pod -This test checks the single level -expansion and collpasing of the +This test checks the single level +expansion and collpasing of the ArrayRef and HashRef type handlers. =cut @@ -23,30 +23,30 @@ ArrayRef and HashRef type handlers. use MooseX::Storage; with Storage; - + has 'number' => (is => 'ro', isa => 'Int'); - + package Foo; use Moose; use MooseX::Storage; - with Storage; + with Storage; - has 'bars' => ( - is => 'ro', - isa => 'ArrayRef' + has 'bars' => ( + is => 'ro', + isa => 'ArrayRef' ); - + package Baz; use Moose; use MooseX::Storage; - with Storage; + with Storage; - has 'bars' => ( - is => 'ro', - isa => 'HashRef' - ); + has 'bars' => ( + is => 'ro', + isa => 'HashRef' + ); } { @@ -54,19 +54,19 @@ ArrayRef and HashRef type handlers. bars => [ map { Bar->new(number => $_) } (1 .. 10) ] ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { __CLASS__ => 'Foo', - bars => [ + bars => [ map { { __CLASS__ => 'Bar', number => $_, - } + } } (1 .. 10) - ], + ], }, '... got the right frozen class' ); @@ -76,15 +76,15 @@ ArrayRef and HashRef type handlers. my $foo = Foo->unpack( { __CLASS__ => 'Foo', - bars => [ + bars => [ map { { __CLASS__ => 'Bar', number => $_, - } + } } (1 .. 10) - ], - } + ], + } ); isa_ok( $foo, 'Foo' ); @@ -100,7 +100,7 @@ ArrayRef and HashRef type handlers. bars => { map { ($_ => Bar->new(number => $_)) } (1 .. 10) } ); isa_ok( $baz, 'Baz' ); - + is_deeply( $baz->pack, { @@ -110,9 +110,9 @@ ArrayRef and HashRef type handlers. ($_ => { __CLASS__ => 'Bar', number => $_, - }) + }) } (1 .. 10) - }, + }, }, '... got the right frozen class' ); @@ -127,10 +127,10 @@ ArrayRef and HashRef type handlers. ($_ => { __CLASS__ => 'Bar', number => $_, - }) + }) } (1 .. 10) - }, - } + }, + } ); isa_ok( $baz, 'Baz' ); diff --git a/t/004_w_cycles.t b/t/004_w_cycles.t index 5e72ec1..f7e60c1 100644 --- a/t/004_w_cycles.t +++ b/t/004_w_cycles.t @@ -15,7 +15,7 @@ BEGIN { This test demonstrates two things: - cycles will not work in the default engine -- you can use a special metaclass to tell +- you can use a special metaclass to tell MooseX::Storage to skip an attribute =cut @@ -34,12 +34,12 @@ This test demonstrates two things: { my $circular = Circular->new; isa_ok($circular, 'Circular'); - + $circular->cycle($circular); - + throws_ok { $circular->pack; - } qr/^Basic Engine does not support cycles/, + } qr/^Basic Engine does not support cycles/, '... cannot collapse a cycle with the basic engine'; } @@ -49,7 +49,7 @@ This test demonstrates two things: throws_ok { Circular->unpack($packed_circular); - } qr/^Basic Engine does not support cycles/, + } qr/^Basic Engine does not support cycles/, '... cannot expand a cycle with the basic engine'; } @@ -62,19 +62,19 @@ This test demonstrates two things: with Storage; has 'node' => (is => 'rw'); - + has 'children' => ( - is => 'ro', - isa => 'ArrayRef', + is => 'ro', + isa => 'ArrayRef', default => sub {[]} ); - + has 'parent' => ( metaclass => 'DoNotSerialize', - is => 'rw', + is => 'rw', isa => 'Tree', ); - + sub add_child { my ($self, $child) = @_; $child->parent($self); @@ -85,28 +85,28 @@ This test demonstrates two things: { my $t = Tree->new(node => 100); isa_ok($t, 'Tree'); - + is_deeply( - $t->pack, + $t->pack, { __CLASS__ => 'Tree', node => 100, children => [], }, '... got the right packed version'); - + my $t2 = Tree->new(node => 200); - isa_ok($t2, 'Tree'); - + isa_ok($t2, 'Tree'); + $t->add_child($t2); - + is_deeply($t->children, [ $t2 ], '... got the right children in $t'); - + is($t2->parent, $t, '... created the cycle correctly'); - isa_ok($t2->parent, 'Tree'); - + isa_ok($t2->parent, 'Tree'); + is_deeply( - $t->pack, + $t->pack, { __CLASS__ => 'Tree', node => 100, @@ -114,18 +114,18 @@ This test demonstrates two things: { __CLASS__ => 'Tree', node => 200, - children => [], - } + children => [], + } ], }, - '... got the right packed version (with parent attribute skipped in child)'); - + '... got the right packed version (with parent attribute skipped in child)'); + is_deeply( - $t2->pack, + $t2->pack, { __CLASS__ => 'Tree', node => 200, - children => [], + children => [], }, '... got the right packed version (with parent attribute skipped)'); } @@ -135,7 +135,7 @@ This test demonstrates two things: use Moose; use MooseX::Storage; with Storage; - + has 'x' => ( is => 'rw', isa => 'HashRef' ); has 'y' => ( is => 'rw', isa => 'HashRef' ); } @@ -154,13 +154,13 @@ This test demonstrates two things: ok( Double->unpack( $pack || {} ), " And unpacked again" ); } - + my $pack = $double->pack( engine_traits => [qw/DisableCycleDetection/] ); ok( $pack, " Object packs when cycle check is disabled"); ok( Double->unpack( $pack ), " And unpacked again" ); -} +} ### the same as above, but now done with a trait ### this fails with cycle detection on @@ -168,7 +168,7 @@ This test demonstrates two things: use Moose; use MooseX::Storage; with Storage( traits => ['DisableCycleDetection'] ); - + has 'x' => ( is => 'rw', isa => 'HashRef' ); has 'y' => ( is => 'rw', isa => 'HashRef' ); } @@ -180,4 +180,4 @@ This test demonstrates two things: ok( $pack, "Object packs with DisableCycleDetection trait"); ok( DoubleNoCycle->unpack( $pack ), " Unpacked again" ); -} +} diff --git a/t/005_w_versions_and_authority_check.t b/t/005_w_versions_and_authority_check.t index 7acdfbe..9dba061 100644 --- a/t/005_w_versions_and_authority_check.t +++ b/t/005_w_versions_and_authority_check.t @@ -12,7 +12,7 @@ BEGIN { =pod -This tests that the version and authority +This tests that the version and authority checks are performed upon object expansion. =cut @@ -21,27 +21,27 @@ checks are performed upon object expansion. package Bar; use Moose; use MooseX::Storage; - + our $VERSION = '0.01'; our $AUTHORITY = 'cpan:JRANDOM'; with Storage; - + has 'number' => (is => 'ro', isa => 'Int'); - + package Foo; use Moose; use MooseX::Storage; our $VERSION = '0.01'; - our $AUTHORITY = 'cpan:JRANDOM'; + our $AUTHORITY = 'cpan:JRANDOM'; - with Storage; + with Storage; - has 'bar' => ( - is => 'ro', - isa => 'Bar' - ); + has 'bar' => ( + is => 'ro', + isa => 'Bar' + ); } { @@ -49,7 +49,7 @@ checks are performed upon object expansion. bar => Bar->new(number => 1) ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { @@ -57,7 +57,7 @@ checks are performed upon object expansion. bar => { __CLASS__ => 'Bar-0.01-cpan:JRANDOM', number => 1, - } + } }, '... got the right frozen class' ); @@ -70,16 +70,16 @@ checks are performed upon object expansion. bar => { __CLASS__ => 'Bar-0.01-cpan:JRANDOM', number => 1, - } - }, + } + }, ); isa_ok( $foo, 'Foo' ); isa_ok( $foo->bar, 'Bar' ); is( $foo->bar->number, 1 , '... got the right number too' ); - + } -Moose::Meta::Class->create('Bar', +Moose::Meta::Class->create('Bar', version => '0.02', authority => 'cpan:JRANDOM', ); @@ -91,12 +91,12 @@ dies_ok { bar => { __CLASS__ => 'Bar-0.01-cpan:JRANDOM', number => 1, - } - } + } + } ); } '... could not unpack, versions are different ' . $@; -Moose::Meta::Class->create('Bar', +Moose::Meta::Class->create('Bar', version => '0.01', authority => 'cpan:DSTATIC', ); @@ -108,7 +108,7 @@ dies_ok { bar => { __CLASS__ => 'Bar-0.01-cpan:JRANDOM', number => 1, - } - } + } + } ); } '... could not unpack, authorities are different'; diff --git a/t/006_w_custom_type_handlers.t b/t/006_w_custom_type_handlers.t index 2e28a81..d4f19b8 100644 --- a/t/006_w_custom_type_handlers.t +++ b/t/006_w_custom_type_handlers.t @@ -8,29 +8,29 @@ use Test::Exception; BEGIN { use_ok('MooseX::Storage'); - use_ok('MooseX::Storage::Engine'); + use_ok('MooseX::Storage::Engine'); } =pod -This is just a simple example of defining +This is just a simple example of defining a custom type handler to take care of custom -inflate and deflate needs. +inflate and deflate needs. =cut { package Bar; use Moose; - + has 'baz' => (is => 'rw', isa => 'Str'); - has 'boo' => (is => 'rw', isa => 'Str'); - + has 'boo' => (is => 'rw', isa => 'Str'); + sub encode { my $self = shift; $self->baz . '|' . $self->boo; } - + sub decode { my ($class, $packed) = @_; my ($baz, $boo) = split /\|/ => $packed; @@ -39,20 +39,20 @@ inflate and deflate needs. boo => $boo, ); } - + MooseX::Storage::Engine->add_custom_type_handler( 'Bar' => ( expand => sub { Bar->decode(shift) }, collapse => sub { (shift)->encode }, ) ); - + package Foo; use Moose; use MooseX::Storage; - + with Storage; - + has 'bar' => ( is => 'ro', isa => 'Bar', @@ -81,9 +81,9 @@ $foo->pack, bar => "BAZ|BOO", }); isa_ok($foo, 'Foo'); - - isa_ok($foo->bar, 'Bar'); - + + isa_ok($foo->bar, 'Bar'); + is($foo->bar->baz, 'BAZ', '... got the right stuff'); is($foo->bar->boo, 'BOO', '... got the right stuff'); } diff --git a/t/007_false.t b/t/007_false.t index 147e498..1b19ea6 100644 --- a/t/007_false.t +++ b/t/007_false.t @@ -29,9 +29,9 @@ BEGIN { boolean => 0, ); isa_ok( $foo, 'Foo' ); - + is($foo->boolean, 0, '... got the right boolean value'); - + is_deeply( $foo->pack, { @@ -51,7 +51,7 @@ BEGIN { number => 0, string => '', boolean => 0, - } + } ); isa_ok( $foo, 'Foo' ); diff --git a/t/008_do_not_serialize.t b/t/008_do_not_serialize.t index 4e2e896..4df3889 100644 --- a/t/008_do_not_serialize.t +++ b/t/008_do_not_serialize.t @@ -20,30 +20,30 @@ BEGIN { has 'bar' => ( metaclass => 'DoNotSerialize', is => 'rw', - default => sub { 'BAR' } + default => sub { 'BAR' } ); - + has 'baz' => ( traits => [ 'DoNotSerialize' ], is => 'rw', - default => sub { 'BAZ' } - ); - + default => sub { 'BAZ' } + ); + has 'gorch' => ( - is => 'rw', + is => 'rw', default => sub { 'GORCH' } - ); + ); 1; } { my $foo = Foo->new; isa_ok($foo, 'Foo'); - + is($foo->bar, 'BAR', '... got the value we expected'); is($foo->baz, 'BAZ', '... got the value we expected'); is($foo->gorch, 'GORCH', '... got the value we expected'); - + is_deeply( $foo->pack, { @@ -67,36 +67,36 @@ BEGIN { is => 'rw', isa => 'Object', # type constraint is important ); - + has zot => ( default => sub { $$ }, is => 'rw', - ); + ); } { my $obj = bless {}; my $bar = Bar->new( foo => $obj ); - + ok( $bar, "New object created" ); is( $bar->foo, $obj, " ->foo => $obj" ); is( $bar->zot, $$, " ->zot => $$" ); - + my $bpack = $bar->pack; is_deeply( $bpack, { __CLASS__ => 'Bar', zot => $$, }, " Packed correctly" ); - + eval { Bar->unpack( $bpack ) }; ok( $@, " Unpack without required attribute fails" ); like( $@, qr/foo/, " Proper error recorded" ); - + my $bar2 = Bar->unpack( $bpack, inject => { foo => bless {} } ); - ok( $bar2, " Unpacked correctly with foo => Object"); -} - - - - + ok( $bar2, " Unpacked correctly with foo => Object"); +} + + + + diff --git a/t/009_do_not_serialize_lazy.t b/t/009_do_not_serialize_lazy.t index 527f258..54331bf 100644 --- a/t/009_do_not_serialize_lazy.t +++ b/t/009_do_not_serialize_lazy.t @@ -19,8 +19,8 @@ BEGIN { has 'x' => (is => 'rw', lazy_build => 1 ); has 'y' => (is => 'rw', lazy_build => 1 ); has 'z' => (is => 'rw', builder => '_build_z' ); - - + + sub _build_x { 'x' } sub _build_y { 'y' } sub _build_z { 'z' } @@ -37,8 +37,8 @@ is( $href->{'x'}, $$, " x => $$" ); is( $href->{'z'}, 'z', " z => z" ); ok( not(exists($href->{'y'})), " y does not exist" ); -is_deeply( - $href, +is_deeply( + $href, { '__CLASS__' => 'Point', 'x' => $$, 'z' => 'z' diff --git a/t/010_basic_json.t b/t/010_basic_json.t index 05d64f5..db190fc 100644 --- a/t/010_basic_json.t +++ b/t/010_basic_json.t @@ -5,11 +5,11 @@ use warnings; use Test::More; -BEGIN { +BEGIN { eval "use Test::JSON"; - plan skip_all => "Test::JSON is required for this test" if $@; + plan skip_all => "Test::JSON is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; + plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 12; use_ok('MooseX::Storage'); } diff --git a/t/011_basic_json_w_utf8.t b/t/011_basic_json_w_utf8.t index b8d4c91..346325e 100644 --- a/t/011_basic_json_w_utf8.t +++ b/t/011_basic_json_w_utf8.t @@ -7,18 +7,18 @@ use Test::More; BEGIN { eval "use Encode"; - plan skip_all => "Encode is required for this test" if $@; + plan skip_all => "Encode is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - # NOTE: - # this is because JSON::XS is + plan skip_all => "JSON::Any is required for this test" if $@; + # NOTE: + # this is because JSON::XS is # the only one which really gets # utf8 correct - # - SL - BEGIN { + # - SL + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); - $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + $ENV{JSON_ANY_CONFIG} = "utf8=1"; + } plan tests => 16; use_ok('MooseX::Storage'); } @@ -29,7 +29,7 @@ BEGIN { use MooseX::Storage; with Storage( 'format' => 'JSON' ); - + has 'utf8_string' => ( is => 'rw', isa => 'Str', @@ -49,14 +49,14 @@ BEGIN { my $foo2 = Foo->thaw($json); isa_ok( $foo, 'Foo' ); - - is($foo2->utf8_string, - "ネットスーパー (Internet Shopping)", + + is($foo2->utf8_string, + "ネットスーパー (Internet Shopping)", '... got the string we expected'); - + is($foo2->freeze, '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}', - '... got the right JSON'); + '... got the right JSON'); } { @@ -66,15 +66,15 @@ BEGIN { $test_string = "ネットスーパー (Internet Shopping)"; no utf8; } - + ok(utf8::is_utf8($test_string), '... got a utf8 string'); - ok(utf8::valid($test_string), '... got a valid utf8 string'); - + ok(utf8::valid($test_string), '... got a valid utf8 string'); + Encode::_utf8_off($test_string); - + ok(!utf8::is_utf8($test_string), '... no longer is utf8 string'); - ok(utf8::valid($test_string), '... got a valid utf8 string'); - + ok(utf8::valid($test_string), '... got a valid utf8 string'); + my $foo = Foo->new( utf8_string => $test_string ); @@ -84,11 +84,11 @@ BEGIN { ok(utf8::valid($foo->utf8_string), '... but is a valid utf8 string'); my $json = $foo->freeze; - + ok(utf8::is_utf8($json), '... is a utf8 string now'); - ok(utf8::valid($json), '... got a valid utf8 string'); + ok(utf8::valid($json), '... got a valid utf8 string'); is($json, '{"__CLASS__":"Foo","utf8_string":"ネットスーパー (Internet Shopping)"}', - '... got the right JSON'); + '... got the right JSON'); } diff --git a/t/012_param_json.t b/t/012_param_json.t index fce71a8..5ce5c24 100644 --- a/t/012_param_json.t +++ b/t/012_param_json.t @@ -5,7 +5,7 @@ use warnings; use Test::More; -BEGIN { +BEGIN { local $@; plan skip_all => "MooseX::Storage::Format::JSONpm required for this test" unless eval "require MooseX::Storage::Format::JSONpm; 1"; diff --git a/t/020_basic_yaml.t b/t/020_basic_yaml.t index 4208d6b..87e3fae 100644 --- a/t/020_basic_yaml.t +++ b/t/020_basic_yaml.t @@ -7,9 +7,9 @@ use Test::More; BEGIN { eval "use Test::YAML::Valid"; - plan skip_all => "Test::YAML::Valid is required for this test" if $@; + plan skip_all => "Test::YAML::Valid is required for this test" if $@; eval "use Best [[qw(YAML::Syck YAML)]]"; - plan skip_all => "YAML or YAML::syck and Best are required for this test" if $@; + plan skip_all => "YAML or YAML::syck and Best are required for this test" if $@; plan tests => 12; use_ok('MooseX::Storage'); } @@ -47,9 +47,9 @@ BEGIN { is( $yaml, - q{--- + q{--- __CLASS__: Foo -array: +array: - 1 - 2 - 3 @@ -61,7 +61,7 @@ array: - 9 - 10 float: 10.5 -hash: +hash: 1: ~ 10: ~ 2: ~ @@ -73,7 +73,7 @@ hash: 8: ~ 9: ~ number: 10 -object: +object: __CLASS__: Foo number: 2 string: foo @@ -85,9 +85,9 @@ string: foo { my $foo = Foo->thaw( - q{--- + q{--- __CLASS__: Foo -array: +array: - 1 - 2 - 3 @@ -99,7 +99,7 @@ array: - 9 - 10 float: 10.5 -hash: +hash: 1: ~ 10: ~ 2: ~ @@ -111,7 +111,7 @@ hash: 8: ~ 9: ~ number: 10 -object: +object: __CLASS__: Foo number: 2 string: foo diff --git a/t/030_with_checksum.t b/t/030_with_checksum.t index 842f7fe..9892500 100644 --- a/t/030_with_checksum.t +++ b/t/030_with_checksum.t @@ -9,9 +9,9 @@ use Test::Deep; BEGIN { eval "use Digest; use Digest::SHA1"; - plan skip_all => "Digest and Digest::SHA1 is required for this test" if $@; + plan skip_all => "Digest and Digest::SHA1 is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; + plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 26; use_ok('MooseX::Storage'); } @@ -42,9 +42,9 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + my $packed = $foo->pack; - + cmp_deeply( $packed, { @@ -55,11 +55,11 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - __DIGEST__ => re('[0-9a-f]+'), - number => 2 - }, + object => { + __CLASS__ => 'Foo', + __DIGEST__ => re('[0-9a-f]+'), + number => 2 + }, }, '... got the right frozen class' ); @@ -69,7 +69,7 @@ BEGIN { $foo2 = Foo->unpack($packed); } '... unpacked okay'; isa_ok($foo2, 'Foo'); - + cmp_deeply( $foo2->pack, { @@ -80,14 +80,14 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - __DIGEST__ => re('[0-9a-f]+'), - number => 2 - }, + object => { + __CLASS__ => 'Foo', + __DIGEST__ => re('[0-9a-f]+'), + number => 2 + }, }, '... got the right frozen class' - ); + ); } { diff --git a/t/040_basic_utils.t b/t/040_basic_utils.t index 8f08b13..1b65efd 100644 --- a/t/040_basic_utils.t +++ b/t/040_basic_utils.t @@ -7,7 +7,7 @@ use Test::More tests => 5; BEGIN { use_ok('MooseX::Storage'); - use_ok('MooseX::Storage::Util'); + use_ok('MooseX::Storage::Util'); } my $packed = { @@ -17,16 +17,16 @@ my $packed = { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, + object => { + __CLASS__ => 'Foo', + number => 2 + }, }; my $json = '{"array":[1,2,3,4,5,6,7,8,9,10],"hash":{"6":null,"3":null,"7":null,"9":null,"2":null,"8":null,"1":null,"4":null,"10":null,"5":null},"float":10.5,"object":{"number":2,"__CLASS__":"Foo"},"number":10,"__CLASS__":"Foo","string":"foo"}'; -my $yaml = q{--- +my $yaml = q{--- __CLASS__: Foo -array: +array: - 1 - 2 - 3 @@ -38,7 +38,7 @@ array: - 9 - 10 float: 10.5 -hash: +hash: 1: ~ 10: ~ 2: ~ @@ -50,38 +50,38 @@ hash: 8: ~ 9: ~ number: 10 -object: +object: __CLASS__: Foo number: 2 string: foo }; -is('Foo', MooseX::Storage::Util->peek($packed), +is('Foo', MooseX::Storage::Util->peek($packed), '... got the right class name from the packed item'); SKIP: { - my $classname = eval { - MooseX::Storage::Util->peek($json => ('format' => 'JSON')) + my $classname = eval { + MooseX::Storage::Util->peek($json => ('format' => 'JSON')) }; if ($@ =~ /^Could not load JSON module because/) { skip "No JSON module found", 1; } - is('Foo', $classname, + is('Foo', $classname, '... got the right class name from the json item'); } SKIP: { - my $classname = eval { + my $classname = eval { MooseX::Storage::Util->peek($yaml => ('format' => 'YAML')) }; if ($@ =~ /^Could not load YAML module because/ or $@ =~ /^Can't locate Best/ ) { skip "No YAML module found", 1; - } - - is('Foo', $classname, + } + + is('Foo', $classname, '... got the right class name from the yaml item'); } diff --git a/t/050_basic_storable.t b/t/050_basic_storable.t index 1ae7a2a..7c98748 100644 --- a/t/050_basic_storable.t +++ b/t/050_basic_storable.t @@ -36,7 +36,7 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + my $stored = $foo->freeze; my $struct = Storable::thaw($stored); @@ -46,9 +46,9 @@ BEGIN { '__CLASS__' => 'Foo', 'float' => 10.5, 'number' => 10, - 'string' => 'foo', + 'string' => 'foo', 'array' => [ 1 .. 10], - 'hash' => { map { $_ => undef } 1 .. 10 }, + 'hash' => { map { $_ => undef } 1 .. 10 }, 'object' => { '__CLASS__' => 'Foo', 'number' => 2 @@ -63,15 +63,15 @@ BEGIN { '__CLASS__' => 'Foo', 'float' => 10.5, 'number' => 10, - 'string' => 'foo', + 'string' => 'foo', 'array' => [ 1 .. 10], - 'hash' => { map { $_ => undef } 1 .. 10 }, + 'hash' => { map { $_ => undef } 1 .. 10 }, 'object' => { '__CLASS__' => 'Foo', 'number' => 2 }, }); - + my $foo = Foo->thaw($stored); isa_ok( $foo, 'Foo' ); diff --git a/t/060_basic_deferred.t b/t/060_basic_deferred.t index b60b9bc..9be9b3a 100644 --- a/t/060_basic_deferred.t +++ b/t/060_basic_deferred.t @@ -9,10 +9,10 @@ use Storable; BEGIN { eval "use Test::JSON; use Test::YAML::Valid;"; - plan skip_all => "Test::JSON and Test::YAML::Valid are required for this test" if $@; + plan skip_all => "Test::JSON and Test::YAML::Valid are required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - plan tests => 33; + plan skip_all => "JSON::Any is required for this test" if $@; + plan tests => 33; use_ok('MooseX::Storage'); } @@ -57,7 +57,7 @@ BEGIN { { my $foo = Foo->thaw( '{"array":[1,2,3,4,5,6,7,8,9,10],"hash":{"6":null,"3":null,"7":null,"9":null,"2":null,"8":null,"1":null,"4":null,"10":null,"5":null},"float":10.5,"object":{"number":2,"__CLASS__":"Foo"},"number":10,"__CLASS__":"Foo","string":"foo"}', - { 'format' => 'JSON' } + { 'format' => 'JSON' } ); isa_ok( $foo, 'Foo' ); @@ -86,7 +86,7 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + my $stored = $foo->freeze({ 'format' => 'Storable' }); my $struct = Storable::thaw($stored); @@ -96,9 +96,9 @@ BEGIN { '__CLASS__' => 'Foo', 'float' => 10.5, 'number' => 10, - 'string' => 'foo', + 'string' => 'foo', 'array' => [ 1 .. 10], - 'hash' => { map { $_ => undef } 1 .. 10 }, + 'hash' => { map { $_ => undef } 1 .. 10 }, 'object' => { '__CLASS__' => 'Foo', 'number' => 2 @@ -113,15 +113,15 @@ BEGIN { '__CLASS__' => 'Foo', 'float' => 10.5, 'number' => 10, - 'string' => 'foo', + 'string' => 'foo', 'array' => [ 1 .. 10], - 'hash' => { map { $_ => undef } 1 .. 10 }, + 'hash' => { map { $_ => undef } 1 .. 10 }, 'object' => { '__CLASS__' => 'Foo', 'number' => 2 }, }); - + my $foo = Foo->thaw($stored, { 'format' => 'Storable' }); isa_ok( $foo, 'Foo' ); @@ -157,9 +157,9 @@ BEGIN { is( $yaml, - q{--- + q{--- __CLASS__: Foo -array: +array: - 1 - 2 - 3 @@ -171,7 +171,7 @@ array: - 9 - 10 float: 10.5 -hash: +hash: 1: ~ 10: ~ 2: ~ @@ -183,7 +183,7 @@ hash: 8: ~ 9: ~ number: 10 -object: +object: __CLASS__: Foo number: 2 string: foo @@ -195,9 +195,9 @@ string: foo { my $foo = Foo->thaw( - q{--- + q{--- __CLASS__: Foo -array: +array: - 1 - 2 - 3 @@ -209,7 +209,7 @@ array: - 9 - 10 float: 10.5 -hash: +hash: 1: ~ 10: ~ 2: ~ @@ -221,7 +221,7 @@ hash: 8: ~ 9: ~ number: 10 -object: +object: __CLASS__: Foo number: 2 string: foo diff --git a/t/061_basic_deferred_w_io.t b/t/061_basic_deferred_w_io.t index 704cba8..512c97e 100644 --- a/t/061_basic_deferred_w_io.t +++ b/t/061_basic_deferred_w_io.t @@ -11,9 +11,9 @@ my $dir = tempdir; BEGIN { eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; + plan skip_all => "IO::AtomicFile is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; + plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 20; use_ok('MooseX::Storage'); } @@ -22,15 +22,15 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with 'MooseX::Storage::Deferred'; - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'ro', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); } my $file = catfile($dir, 'temp.json'); diff --git a/t/070_basic_maybe.t b/t/070_basic_maybe.t index 0c908ba..c154327 100644 --- a/t/070_basic_maybe.t +++ b/t/070_basic_maybe.t @@ -37,7 +37,7 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { @@ -48,10 +48,10 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, + object => { + __CLASS__ => 'Foo', + number => 2 + }, }, '... got the right frozen class' ); @@ -67,11 +67,11 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, - } + object => { + __CLASS__ => 'Foo', + number => 2 + }, + } ); isa_ok( $foo, 'Foo' ); @@ -101,25 +101,25 @@ BEGIN { use Scalar::Util 'looks_like_number'; - with Storage; - - subtype 'Natural' + with Storage; + + subtype 'Natural' => as 'Int' => where { $_ > 0 }; - - subtype 'HalfNum' + + subtype 'HalfNum' => as 'Num' - => where { "$_" =~ /\.5$/ }; - + => where { "$_" =~ /\.5$/ }; + subtype 'FooString' => as 'Str' => where { lc($_) eq 'foo' }; - - subtype 'IntArray' + + subtype 'IntArray' => as 'ArrayRef' => where { scalar grep { looks_like_number($_) } @{$_} }; - subtype 'UndefHash' + subtype 'UndefHash' => as 'HashRef' => where { scalar grep { !defined($_) } values %{$_} }; @@ -141,7 +141,7 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + is_deeply( $foo->pack, { @@ -151,10 +151,10 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, + object => { + __CLASS__ => 'Foo', + number => 2 + }, }, '... got the right frozen class' ); @@ -169,11 +169,11 @@ BEGIN { float => 10.5, array => [ 1 .. 10 ], hash => { map { $_ => undef } ( 1 .. 10 ) }, - object => { - __CLASS__ => 'Foo', - number => 2 - }, - } + object => { + __CLASS__ => 'Foo', + number => 2 + }, + } ); isa_ok( $foo, 'Foo' ); diff --git a/t/100_io.t b/t/100_io.t index b1e1504..8874409 100644 --- a/t/100_io.t +++ b/t/100_io.t @@ -8,10 +8,10 @@ use Test::TempDir; use File::Spec::Functions; my $dir = tempdir; -BEGIN { +BEGIN { eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - plan tests => 10; + plan skip_all => "JSON::Any is required for this test" if $@; + plan tests => 10; use_ok('MooseX::Storage'); } @@ -19,15 +19,15 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with Storage(format => 'JSON', io => 'File'); - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'ro', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); } my $file = catfile( $dir, 'temp.json' ); diff --git a/t/101_io_atomic.t b/t/101_io_atomic.t index 43cb6fb..55373a5 100644 --- a/t/101_io_atomic.t +++ b/t/101_io_atomic.t @@ -10,9 +10,9 @@ my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; + plan skip_all => "IO::AtomicFile is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; + plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 10; use_ok('MooseX::Storage'); } @@ -21,15 +21,15 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with Storage(format => 'JSON', io => 'AtomicFile'); - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'ro', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); } my $file = catfile($dir,'temp.json'); diff --git a/t/102_io_storable_file.t b/t/102_io_storable_file.t index 2428df6..2ff5625 100644 --- a/t/102_io_storable_file.t +++ b/t/102_io_storable_file.t @@ -16,15 +16,15 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with Storage(io => 'StorableFile'); - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'ro', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); } my $file = catfile($dir,'temp.storable'); diff --git a/t/103_io_storable_file_custom.t b/t/103_io_storable_file_custom.t index b66563a..87878c3 100644 --- a/t/103_io_storable_file_custom.t +++ b/t/103_io_storable_file_custom.t @@ -17,15 +17,15 @@ BEGIN { package Foo; use Moose; use MooseX::Storage; - + with Storage(io => 'StorableFile'); - + has 'number' => (is => 'ro', isa => 'Int'); has 'string' => (is => 'rw', isa => 'Str'); - has 'float' => (is => 'ro', isa => 'Num'); + has 'float' => (is => 'ro', isa => 'Num'); has 'array' => (is => 'ro', isa => 'ArrayRef'); - has 'hash' => (is => 'ro', isa => 'HashRef'); - has 'object' => (is => 'ro', isa => 'Object'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); ## add some custom freeze/thaw hooks here ... @@ -59,7 +59,7 @@ my $file = catfile($dir,'temp.storable'); isa_ok($foo, 'Foo'); $foo->store($file); - + # check our custom freeze hook fired ... my $data = Storable::retrieve($file); is_deeply( @@ -68,17 +68,17 @@ my $file = catfile($dir,'temp.storable'); '__CLASS__' => 'Foo', 'float' => 10.5, 'number' => 10, - 'string' => 'HELLO WORLD', + 'string' => 'HELLO WORLD', 'array' => [ 1 .. 10], - 'hash' => { map { $_ => undef } 1 .. 10 }, + 'hash' => { map { $_ => undef } 1 .. 10 }, 'object' => { '__CLASS__' => 'Foo', 'number' => 2 }, }, '... got the data struct we expected' - ); - + ); + } { diff --git a/t/104_io_w_utf8.t b/t/104_io_w_utf8.t index b7e9ea7..6cc5ec5 100644 --- a/t/104_io_w_utf8.t +++ b/t/104_io_w_utf8.t @@ -8,18 +8,18 @@ use File::Temp qw(tempdir); use File::Spec::Functions; my $dir = tempdir( CLEANUP => 1 ); -BEGIN { +BEGIN { eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - # NOTE: - # this is because JSON::XS is + plan skip_all => "JSON::Any is required for this test" if $@; + # NOTE: + # this is because JSON::XS is # the only one which really gets # utf8 correct - # - SL - BEGIN { + # - SL + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); - $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + $ENV{JSON_ANY_CONFIG} = "utf8=1"; + } plan tests => 8; use_ok('MooseX::Storage'); } @@ -32,7 +32,7 @@ use utf8; use MooseX::Storage; with Storage( 'format' => 'JSON', 'io' => 'File' ); - + has 'utf8_string' => ( is => 'rw', isa => 'Str', @@ -45,16 +45,16 @@ my $file = catfile($dir,'temp.json'); { my $foo = Foo->new; isa_ok( $foo, 'Foo' ); - - $foo->store($file); + + $foo->store($file); } { my $foo = Foo->load($file); isa_ok($foo, 'Foo'); - is($foo->utf8_string, - "ネットスーパー (Internet Shopping)", + is($foo->utf8_string, + "ネットスーパー (Internet Shopping)", '... got the string we expected'); } @@ -67,18 +67,18 @@ unlink $file; utf8_string => 'Escritório' ); isa_ok( $foo, 'Foo' ); - - $foo->store($file); + + $foo->store($file); } { my $foo = Foo->load($file); isa_ok($foo, 'Foo'); - + ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8'); - is($foo->utf8_string, - "Escritório", + is($foo->utf8_string, + "Escritório", '... got the string we expected'); } diff --git a/t/105_io_atomic_w_utf8.t b/t/105_io_atomic_w_utf8.t index fafc565..d831409 100644 --- a/t/105_io_atomic_w_utf8.t +++ b/t/105_io_atomic_w_utf8.t @@ -8,20 +8,20 @@ use Test::TempDir; use File::Spec::Functions; my $dir = tempdir; -BEGIN { +BEGIN { eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; + plan skip_all => "IO::AtomicFile is required for this test" if $@; eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - # NOTE: - # this is because JSON::XS is + plan skip_all => "JSON::Any is required for this test" if $@; + # NOTE: + # this is because JSON::XS is # the only one which really gets # utf8 correct - # - SL - BEGIN { + # - SL + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); - $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + $ENV{JSON_ANY_CONFIG} = "utf8=1"; + } plan tests => 8; use_ok('MooseX::Storage'); } @@ -34,7 +34,7 @@ use utf8; use MooseX::Storage; with Storage( 'format' => 'JSON', 'io' => 'AtomicFile' ); - + has 'utf8_string' => ( is => 'rw', isa => 'Str', @@ -47,16 +47,16 @@ my $file = catfile($dir, 'temp.json'); { my $foo = Foo->new; isa_ok( $foo, 'Foo' ); - - $foo->store($file); + + $foo->store($file); } { my $foo = Foo->load($file); isa_ok($foo, 'Foo'); - is($foo->utf8_string, - "ネットスーパー (Internet Shopping)", + is($foo->utf8_string, + "ネットスーパー (Internet Shopping)", '... got the string we expected'); } @@ -69,18 +69,18 @@ unlink $file; utf8_string => 'Escritório' ); isa_ok( $foo, 'Foo' ); - - $foo->store($file); + + $foo->store($file); } { my $foo = Foo->load($file); isa_ok($foo, 'Foo'); - + ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8'); - is($foo->utf8_string, - "Escritório", + is($foo->utf8_string, + "Escritório", '... got the string we expected'); }