X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=18fecd6ee2341d3aa2a376c646ac85de9c23dabf;hb=18ef6e1c6698a79fb754a81ee1277c8d9bef80f9;hp=8bd55e5ea751b53953eb3ddcc95f155919f6c9df;hpb=252ab1a26175a028754adbe4589cd87bc5240ce6;p=gitmo%2FMoose-Autobox.git diff --git a/t/001_basic.t b/t/001_basic.t index 8bd55e5..18fecd6 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,14 +3,15 @@ use strict; use warnings; -use Test::More tests => 44; +use Test::More tests => 63; BEGIN { use_ok('Moose::Autobox'); - use_ok('Moose::Autobox::Undef'); } -use autobox UNDEF => 'Moose::Autobox::Undef'; +use Moose::Autobox; + +my $VAR1; # for eval of dumps # SCALAR & UNDEF @@ -20,6 +21,12 @@ ok(!$s->defined, '... got a undefined value'); $s = 5; ok($s->defined, '... got a defined value'); +eval $s->dump; +is($VAR1, 5 , '... eval of SCALAR->dump works'); + +eval $s->perl; +is($s->perl, $s->dump, '... SCALAR->dump equals SCALAR->perl'); + # CODE my $f1 = sub { @_ }; @@ -42,7 +49,10 @@ is_deeply( '... got the right return value from the r-curried function'); ok((sub { 1 })->disjoin(sub { 0 })->(), '... disjoins properly'); +ok((sub { 0 })->disjoin(sub { 1 })->(), '... disjoins properly'); + ok(!(sub { 1 })->conjoin(sub { 0 })->(), '... conjoins properly'); +ok(!(sub { 0 })->conjoin(sub { 1 })->(), '... conjoins properly'); my $compose = (sub { @_, 1 })->compose(sub { @_, 2 }); @@ -50,8 +60,7 @@ is_deeply( [ $compose->() ], [ 1, 2 ], '... got the right return value for compose'); - - + # ARRAY my $a = [ 4, 2, 6, 78, 101, 2, 3 ]; @@ -81,6 +90,7 @@ $a->grep(sub { $_ < 50 }), is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged'); is($a->join(', '), '4, 2, 6, 78, 101, 2, 3', '... got the right joined string'); +is($a->join, '4267810123', '... got the right joined string'); ok($a->exists(0), '... exists works'); ok(!$a->exists(10), '... exists works'); @@ -90,6 +100,12 @@ is_deeply($a, [ 4, 2, 6, 78, 101, 2 ], '... original value is now changed'); is($a->shift(), 4, '... got the right unshift-ed value'); is_deeply($a, [ 2, 6, 78, 101, 2 ], '... original value is now changed'); + +is_deeply( +$a->slice([ 1, 2, 4 ]), +[ 6, 78, 2 ], +'... got the right sliced value'); + is_deeply( $a->unshift(10), [ 10, 2, 6, 78, 101, 2 ], @@ -144,9 +160,36 @@ $a->kv, is([1, 2, 3, 4, 5]->reduce(sub { $_[0] + $_[1] }), 15, '... got the right reduction'); is_deeply( - [1, 2, 3, 4, 5]->zip([ 5, 4, 3, 2, 1 ]), - [ [1, 5], [2, 4], [3, 3], [4, 2], [5, 1] ], - '... got the right zip'); +[1, 2, 3, 4, 5]->zip([ 5, 4, 3, 2, 1 ]), +[ [1, 5], [2, 4], [3, 3], [4, 2], [5, 1] ], +'... got the right zip'); + +is_deeply( +[1, 2, 3, 4, 5]->zip([ 6, 5, 4, 3, 2, 1 ]), +[ [1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [undef, 1] ], +'... got the right zip'); + +is($a->delete(2), 30, '... got the value deleted'); +is_deeply( +$a, +[ 15, 20, undef, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], +'... the value is correctly deleted'); + +$a->put(2, 30); + +is_deeply( +$a, +[ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], +'... the value is correctly put'); + +eval($a->dump); +is_deeply( $VAR1, + [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], + '... the value is correctly dumped'); + +is( $a->dump, + $a->perl, + '... the value is correctly dumped with perl()' ); # Hash @@ -165,7 +208,42 @@ $h->values->sort, [ 1, 2, 3 ], '... the values'); +is_deeply( +$h->kv->sort(sub { $_[0]->[1] <=> $_[1]->[1] }), +[ ['one', 1], ['two', 2], ['three', 3] ], +'... the kvs'); + ok($h->exists('two'), '... exists works'); ok(!$h->exists('five'), '... !exists works'); +$h->put('four' => 4); +is_deeply( +$h, +{ one => 1, two => 2, three => 3, four => 4 }, +'... got the value added correctly'); + +is($h->at('four'), 4, '... got the value at "four"'); + +$h->delete('four'); +is_deeply( +$h, +{ one => 1, two => 2, three => 3 }, +'... got the value deleted correctly'); + +is_deeply( +$h->merge({ three => 33, four => 44 }), +{ one => 1, two => 2, three => 33, four => 44 }, +'... got the hashes merged correctly'); + +eval($h->dump); +is_deeply( $VAR1, + { one => 1, two => 2, three => 3 }, + '... the value is correctly dumped'); + +is( $h->dump, + $h->perl, + '... the value is correctly dumped with perl()' ); +is_deeply( { one => 1, two => 2, three => 3 }->slice([qw/three one/]), + [ qw/3 1/ ], + '... hash slices ok' );