X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=17b81ff40b80a549adc1a81f14ac9172ba844f38;hb=4e008ee1aacc59932f6d7e8643eab442ba3b0979;hp=fc0f00b087f692749cb413e46711bcdea83ea2c2;hpb=c11e6a7483ba10a1f1d407db834163a0637e9ae8;p=gitmo%2FMoose-Autobox.git diff --git a/t/001_basic.t b/t/001_basic.t index fc0f00b..17b81ff 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,14 +3,15 @@ use strict; use warnings; -use Test::More tests => 56; +use Test::More tests => 70; 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,15 @@ 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->flatten; +is($VAR1, 5 , '... eval of SCALAR->flatten works'); + +eval $s->perl; +is($s->perl, $s->dump, '... SCALAR->dump equals SCALAR->perl'); + # CODE my $f1 = sub { @_ }; @@ -68,6 +78,10 @@ $a->map(sub { $_ + 2 }), is_deeply($a, [ 4, 2, 6, 78, 101, 2, 3 ], '... original value is unchanged'); +my $b = [1, 2, 3]; +$b->map(sub { $_++ } ); +is_deeply($b, [ 2, 3, 4 ], '... original value is changed'); + is_deeply( $a->reverse(), [ 3, 2, 101, 78, 6, 2, 4 ], @@ -175,6 +189,20 @@ $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()' ); + +is([1, 2, 3, 4, 5]->any, 3, '... any correctly found a value'); +is([1, 1, 2, 3, 4, 5, 5]->one, 2, '... one correctly found one value'); +is([1, 1, 2, 3, 4, 5, 5]->none , 6, '... none correctly did not find any of a value'); +is([3, 3, 3]->all, 3, '... all correctly found all of a value'); + # Hash my $h = { one => 1, two => 2, three => 3 }; @@ -213,4 +241,24 @@ $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' ); + +is_deeply( { one => 1, two => 2, three => 3 }->hslice([qw/two three/]), + { two => 2, three => 3 }, + '... hash hslices ok' );