From: Vincent Pit Date: Sun, 18 Jan 2009 15:45:45 +0000 (+0100) Subject: Cleanup t/22-len.t X-Git-Tag: v0.27~16 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=280b91534ff4d9ca7596362002cf65145bf15cf3;p=perl%2Fmodules%2FVariable-Magic.git Cleanup t/22-len.t --- diff --git a/t/22-len.t b/t/22-len.t index ec74580..5d3ae92 100644 --- a/t/22-len.t +++ b/t/22-len.t @@ -8,27 +8,33 @@ use Test::More tests => 13; use Variable::Magic qw/wizard cast VMG_COMPAT_SCALAR_LENGTH_NOLEN/; my $c = 0; + my $n = 1 + int rand 1000; my $wiz = wizard len => sub { ++$c; return $n }; -is($c, 0, 'len : create wizard'); +is $c, 0, 'len: wizard() doesn\'t trigger magic'; my @a = qw/a b c/; +$c = 0; cast @a, $wiz; -is($c, 0, 'len : cast on array'); +is $c, 0, 'len: cast on array doesn\'t trigger magic'; +$c = 0; my $b = scalar @a; -is($c, 1, 'len : get array length'); -is($b, $n, 'len : get array length correctly'); +is $c, 1, 'len: get array length triggers magic correctly'; +is $b, $n, 'len: get array length correctly'; +$c = 0; $b = $#a; -is($c, 2, 'len : get last array index'); -is($b, $n - 1, 'len : get last array index correctly'); +is $c, 1, 'len: get last array index triggers magic correctly'; +is $b, $n - 1, 'len: get last array index correctly'; $n = 0; + +$c = 0; $b = scalar @a; -is($c, 3, 'len : get array length 0'); -is($b, 0, 'len : get array length 0 correctly'); +is $c, 1, 'len: get array length 0 triggers magic correctly'; +is $b, 0, 'len: get array length 0 correctly'; SKIP: { skip 'length() no longer calls mg_len magic' => 5 if VMG_COMPAT_SCALAR_LENGTH_NOLEN; @@ -36,20 +42,24 @@ SKIP: { $c = 0; $n = 1 + int rand 1000; # length magic on scalars needs also get magic to be triggered. - $wiz = wizard get => sub { return 56478 }, + $wiz = wizard get => sub { return 'anything' }, len => sub { ++$c; return $n }; my $x = int rand 1000; + $c = 0; cast $x, $wiz; - is($c, 0, 'len : cast on scalar'); + is $c, 0, 'len: cast on scalar doesn\'t trigger magic'; + $c = 0; $b = length $x; - is($c, 1, 'len : get scalar length'); - is($b, $n, 'len : get scalar length correctly'); + is $c, 1, 'len: get scalar length triggers magic correctly'; + is $b, $n, 'len: get scalar length correctly'; $n = 0; + + $c = 0; $b = length $x; - is($c, 2, 'len : get scalar length 0'); - is($b, $n, 'len : get scalar length 0 correctly'); + is $c, 1, 'len: get scalar length 0 triggers magic correctly'; + is $b, $n, 'len: get scalar length 0 correctly'; }