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');
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');
}