X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F31-vcopy-copy.t;h=00f289702fd685d44ceeffc2ad81150ad166cb0d;hb=4dc1aa8932c595136b763a34207e4e9ee683dc53;hp=2d1132d4a5e3843525a3313990830973f4d49f76;hpb=f77706f0734eb34a9623cc492b5d73061fba9b62;p=perl%2Fmodules%2FScalar-Vec-Util.git diff --git a/t/31-vcopy-copy.t b/t/31-vcopy-copy.t index 2d1132d..00f2897 100644 --- a/t/31-vcopy-copy.t +++ b/t/31-vcopy-copy.t @@ -3,39 +3,45 @@ use strict; use warnings; -use Test::More 'no_plan'; +use lib 't/lib'; +use Test::Leaner 'no_plan'; -use Scalar::Vec::Util qw/vcopy SVU_SIZE/; +use Scalar::Vec::Util qw; -eval { vcopy undef, 0, my $y, 0, 0 }; -like($@, qr/Invalid\s+argument/, 'first argument undef croaks'); -eval { vcopy my $x, undef, my $y, 0, 0 }; -like($@, qr/Invalid\s+argument/, 'second argument undef croaks'); -eval { vcopy my $x, 0, undef, 0, 0 }; -like($@, qr/Invalid\s+argument/, 'third argument undef croaks'); -eval { vcopy my $x, 0, my $y, undef, 0 }; -like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks'); -eval { vcopy my $x, 0, my $y, 0, undef }; -like($@, qr/Invalid\s+argument/, 'fifth argument undef croaks'); +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + +for ([ 1, 'offset', -1 ], [ 3, 'offset', -1 ], [ 4, 'length', -1 ]) { + my @args = (~0) x 5; + $args[$_->[0]] = $_->[2]; + local $@; + eval { &vcopy(@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/, + "vcopy(@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; } -} +} my ($f, $t, $c) = ('') x 3; @@ -43,13 +49,13 @@ my @s = ($p - $q) .. ($p + $q); for my $s1 (@s) { for my $s2 (@s) { for my $l (0 .. $n - 1) { - last if $s1 + $l > $n or $s2 + $l > $n; + my $desc = "vcopy $s1, $s2, $l"; pat $f, $s1, $l, 0; rst $t; pat $c, $s2, $l, 0; vcopy $f => $s1, $t => $s2, $l; - ok(myeq($t, 0, $c, 0, $n), "vcopy $s1, $s2, $l"); - is(length $t, length $c, "length is ok"); + is length $t, length $c, "$desc: length"; + ok myeq($t, 0, $c, 0, $n), "$desc: bits"; } } }