X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F22-len.t;h=ab19730c7492c0a653070b3f8365b8c581b3a80f;hb=4de8639a5eb25d672b6248bd80e433abd0a267e2;hp=a35375fb21a1dcbcae9775d82b0273a34707dc03;hpb=3bc98bdbdb230943e7fb3135e325f10013acac2d;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/22-len.t b/t/22-len.t index a35375f..ab19730 100644 --- a/t/22-len.t +++ b/t/22-len.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 39 + (2 * 2 + 1); +use Test::More tests => 39 + (2 * 2 + 1) + (5 + 2 * 3); use Variable::Magic qw; @@ -70,8 +70,8 @@ SKIP: { $c = 0; $n = 1 + int rand 1000; # length magic on scalars needs also get magic to be triggered. - $wiz = wizard get => sub { return 'anything' }, - len => sub { $d = $_[2]; ++$c; return $n }; + my $wiz = wizard get => sub { return 'anything' }, + len => sub { $d = $_[2]; ++$c; return $n }; my $x = 6789; @@ -167,3 +167,35 @@ SKIP: { dispell @val, $wv; is_deeply \@val, [ 4, 5, 8 ], 'len: after value'; } + +{ + local $@; + + my $wua = eval { wizard len => \undef }; + is $@, '', 'len: noop wizard (for arrays) creation does not croak'; + + my @a = ('a' .. 'z'); + eval { cast @a, $wua }; + is $@, '', 'len: noop wizard (for arrays) cast does not croak'; + + my $l; + eval { $l = $#a }; + is $@, '', 'len: noop wizard (for arrays) invocation does not croak'; + is $l, 25, 'len: noop magic on an array returns the previous length'; + + my $wus = eval { wizard get => \undef, len => \undef }; + is $@, '', 'len: noop wizard (for strings) creation does not croak'; + + for ([ 'euro', 'string' ], [ "\x{20AC}uro", 'unicode string' ]) { + my ($euro, $desc) = @$_; + + eval { cast $euro, $wus }; + is $@, '', 'len: noop wizard (for strings) cast does not croak'; + + eval { pos($euro) = 2 }; + is $@, '', 'len: noop wizard (for strings) invocation does not croak'; + + my ($rest) = ($euro =~ /(.*)/g); + is $rest, 'ro', "len: noop magic on a $desc returns the previous length"; + } +}