From: Vincent Pit Date: Sat, 24 Jan 2009 15:08:56 +0000 (+0100) Subject: More tests for t/31-array.t X-Git-Tag: v0.28~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=0c555be0dab6fe6582f787cc03e82fd460bcd59c;p=perl%2Fmodules%2FVariable-Magic.git More tests for t/31-array.t Including tests of exists and delete. --- diff --git a/t/31-array.t b/t/31-array.t index 1c8f037..b98decc 100644 --- a/t/31-array.t +++ b/t/31-array.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2 * 25 + 9 + 1; +use Test::More tests => 2 * 27 + 13 + 1; use Variable::Magic qw/cast dispell VMG_COMPAT_ARRAY_PUSH_NOLEN VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID VMG_COMPAT_ARRAY_UNDEF_CLEAR/; @@ -37,12 +37,26 @@ check { @a = qw/a b d/ } { set => 3, clear => 1 }, 'assign'; check { $a[2] = 'c' } { }, 'assign old element'; -check { $a[3] = 'd' } { set => 1 }, 'assign new element'; +check { $a[4] = 'd' } { set => 1 }, 'assign new element'; + +$b = check { exists $a[4] } { }, 'exists'; +is $b, 1, 'array: exists correctly'; + +$b = check { delete $a[4] } { set => 1 }, 'delete'; +is $b, 'd', 'array: delete correctly'; + +$b = check { @a } { len => 1 }, 'length @'; +is $b, 3, 'array: length @ correctly'; + +$b = check { $#a } { len => 1 }, 'length $#'; +is $b, 2, 'array: length $# correctly'; check { push @a, 'x'; () } { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN },'push (void)'; + $b = check { push @a, 'y' } { set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN }, 'push (scalar)'; +is $b, 5, 'array: push (scalar) correctly'; $b = check { pop @a } { set => 1, len => 1 }, 'pop'; is $b, 'y', 'array: pop correctly'; @@ -52,22 +66,17 @@ check { unshift @a, 'z'; () } 'unshift (void)'; $b = check { unshift @a, 't' } { set => 1, len => 1 }, 'unshift (scalar)'; +is $b, 6, 'unshift (scalar) correctly'; $b = check { shift @a } { set => 1, len => 1 }, 'shift'; is $b, 't', 'array: shift correctly'; -$b = check { @a } { len => 1 }, 'length @'; -is $b, 6, 'array: length @ correctly'; - -$b = check { $#a } { len => 1 }, 'length $#'; -is $b, 5, 'array: length $# correctly'; - -check { my $i; @a = map ++$i, @a; () } { set => 6, len => 1, clear => 1}, 'map'; +check { my $i; @a = map ++$i, @a; () } { set => 5, len => 1, clear => 1}, 'map'; @b = check { grep { $_ >= 4 } @a } { len => 1 }, 'grep'; -is_deeply \@b, [ 4 .. 6 ], 'array: grep correctly'; +is_deeply \@b, [ 4 .. 5 ], 'array: grep correctly'; -check { 1 for @a } { len => 6 + 1 }, 'for'; +check { 1 for @a } { len => 5 + 1 }, 'for'; check { my @b = @n;