X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F22-len.t;fp=t%2F22-len.t;h=ec74580a488a7bb4592bf49414f6b847b25f2f99;hb=d12adc8d9392ea952a40cb7e46df8809256e8b48;hp=8ea332c5fc8603ff3405370699604bcd62aba468;hpb=040a327bd3b1c223b36d0013546d4970b4d9580e;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/22-len.t b/t/22-len.t index 8ea332c..ec74580 100644 --- a/t/22-len.t +++ b/t/22-len.t @@ -3,12 +3,12 @@ use strict; use warnings; -use Test::More tests => 11; +use Test::More tests => 13; use Variable::Magic qw/wizard cast VMG_COMPAT_SCALAR_LENGTH_NOLEN/; my $c = 0; -my $n = int rand 1000; +my $n = 1 + int rand 1000; my $wiz = wizard len => sub { ++$c; return $n }; is($c, 0, 'len : create wizard'); @@ -30,21 +30,26 @@ $b = scalar @a; is($c, 3, 'len : get array length 0'); is($b, 0, 'len : get array length 0 correctly'); -$c = 0; -$n = int rand 1000; -# length magic on scalars needs also get magic to be triggered. -$wiz = wizard get => sub { return 56478 }, - len => sub { ++$c; return $n }; +SKIP: { + skip 'length() no longer calls mg_len magic' => 5 if VMG_COMPAT_SCALAR_LENGTH_NOLEN; -my $x = int rand 1000; + $c = 0; + $n = 1 + int rand 1000; + # length magic on scalars needs also get magic to be triggered. + $wiz = wizard get => sub { return 56478 }, + len => sub { ++$c; return $n }; -SKIP: { - skip 'length() no longer calls mg_len magic', 3 if VMG_COMPAT_SCALAR_LENGTH_NOLEN; + my $x = int rand 1000; cast $x, $wiz; is($c, 0, 'len : cast on scalar'); $b = length $x; - is($c, 1, 'len : get scalar length'); - is($b, $n - 1, 'len : get scalar length correctly'); + is($c, 1, 'len : get scalar length'); + is($b, $n, 'len : get scalar length correctly'); + + $n = 0; + $b = length $x; + is($c, 2, 'len : get scalar length 0'); + is($b, $n, 'len : get scalar length 0 correctly'); }