6 use Test::More tests => 13;
8 use Variable::Magic qw/wizard cast VMG_COMPAT_SCALAR_LENGTH_NOLEN/;
12 my $n = 1 + int rand 1000;
13 my $wiz = wizard len => sub { ++$c; return $n };
14 is $c, 0, 'len: wizard() doesn\'t trigger magic';
20 is $c, 0, 'len: cast on array doesn\'t trigger magic';
24 is $c, 1, 'len: get array length triggers magic correctly';
25 is $b, $n, 'len: get array length correctly';
29 is $c, 1, 'len: get last array index triggers magic correctly';
30 is $b, $n - 1, 'len: get last array index correctly';
36 is $c, 1, 'len: get array length 0 triggers magic correctly';
37 is $b, 0, 'len: get array length 0 correctly';
40 skip 'length() no longer calls mg_len magic' => 5 if VMG_COMPAT_SCALAR_LENGTH_NOLEN;
43 $n = 1 + int rand 1000;
44 # length magic on scalars needs also get magic to be triggered.
45 $wiz = wizard get => sub { return 'anything' },
46 len => sub { ++$c; return $n };
48 my $x = int rand 1000;
52 is $c, 0, 'len: cast on scalar doesn\'t trigger magic';
56 is $c, 1, 'len: get scalar length triggers magic correctly';
57 is $b, $n, 'len: get scalar length correctly';
63 is $c, 1, 'len: get scalar length 0 triggers magic correctly';
64 is $b, $n, 'len: get scalar length 0 correctly';