X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-vfill.t;h=3b6a27a837f5d5e14ad2eb6235111e1eded9042b;hb=HEAD;hp=33565f954bcb9b89adee5a838ad396a25ef0019c;hpb=f77706f0734eb34a9623cc492b5d73061fba9b62;p=perl%2Fmodules%2FScalar-Vec-Util.git diff --git a/t/21-vfill.t b/t/21-vfill.t index 33565f9..3b6a27a 100644 --- a/t/21-vfill.t +++ b/t/21-vfill.t @@ -5,33 +5,40 @@ use warnings; use Test::More 'no_plan'; -use Scalar::Vec::Util qw/vfill SVU_SIZE/; +use Scalar::Vec::Util qw; -eval { vfill undef, 0, 0, 0 }; -like($@, qr/Invalid\s+argument/, 'first argument undef croaks'); -eval { vfill my $x, undef, 0, 0 }; -like($@, qr/Invalid\s+argument/, 'second argument undef croaks'); -eval { vfill my $x, 0, undef, 0 }; -like($@, qr/Invalid\s+argument/, 'third argument undef croaks'); -eval { vfill my $x, 0, 0, undef }; -like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks'); +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + +for ([ 1, 'offset', -1 ], [ 2, 'length', '-1' ]) { + my @args = (~0) x 4; + $args[$_->[0]] = $_->[2]; + local $@; + eval { &vfill(@args) }; + my $err = $@; + my $line = __LINE__-2; + like $err, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/, + "vfill(@args) failed"; +} my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 1; -*myfill = *Scalar::Vec::Util::vfill_pp; -*myeq = *Scalar::Vec::Util::veq_pp; - -sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' } +sub rst { + myfill $_[0], 0, $n, 0; + $_[0] = ''; +} sub pat { - (undef, my $a, my $b, my $x) = @_; + my (undef, $a, $b, $x) = @_; $_[0] = ''; if ($b) { - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; } } @@ -41,10 +48,11 @@ my @s = ($p - $q) .. ($p + $q); for my $s (@s) { for my $l (0 .. $n - 1) { next if $s + $l > $n; + my $desc = "vfill $s, $l"; pat $c, $s, $l, 0; rst $v; vfill $v, $s, $l, 1; - ok(myeq($v, 0, $c, 0, $n), "vfill $s, $l"); - is(length $v, length $c, "length is ok"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits"; } }