X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScalar-Vec-Util.git;a=blobdiff_plain;f=t%2F40-vshift.t;h=b45ffc1ac4bd344991889db01ac1c02ab1f40530;hp=15d1decb7912af527e565e3a77343c96eba8397b;hb=2bade59206c8f2bd2ed64e1faa8b10cc9109b734;hpb=eb5fc894300e2e78d7beeb03f47f9d8e488518d5 diff --git a/t/40-vshift.t b/t/40-vshift.t index 15d1dec..b45ffc1 100644 --- a/t/40-vshift.t +++ b/t/40-vshift.t @@ -8,46 +8,55 @@ use Test::Leaner 'no_plan'; use Scalar::Vec::Util qw; +BEGIN { + *myfill = *Scalar::Vec::Util::vfill_pp; + *myeq = *Scalar::Vec::Util::veq_pp; +} + for ([ 1, 'offset', -1 ], [ 2, 'length', '-1' ]) { my @args = ('1') x 4; $args[$_->[0]] = $_->[2]; - eval { &vshift(@args) }; my $line = __LINE__; - like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/; + local $@; + eval { &vshift(@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/, + "vshift(@args) failed"; } my $p = SVU_SIZE; -$p = 8 if $p < 8; +$p = 8 if $p < 8; my $n = 3 * $p; my $q = 2; -*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] = ''; $x = $x ? 1 : 0; if (defined $b) { - myfill($_[0], 0, $a, $x); - myfill($_[0], $a, $b, 1 - $x); + myfill $_[0], 0, $a, $x; + myfill $_[0], $a, $b, 1 - $x; } } sub expect { - (undef, my $s, my $l, my $b, my $left, my $insert) = @_; - myfill($_[0], 0, $s, 0); + my (undef, $s, $l, $b, $left, $insert) = @_; + myfill $_[0], 0, $s, 0; if ($b < $l) { if ($left) { - myfill($_[0], $s, $b, defined $insert ? $insert : 1); - myfill($_[0], $s + $b, $l - $b, 1); + myfill $_[0], $s, $b, defined $insert ? $insert : 1; + myfill $_[0], $s + $b, $l - $b, 1; } else { - myfill($_[0], $s, $l - $b, 1); - myfill($_[0], $s + $l - $b, $b, defined $insert ? $insert : 1); + myfill $_[0], $s, $l - $b, 1; + myfill $_[0], $s + $l - $b, $b, defined $insert ? $insert : 1; } } else { - myfill($_[0], $s, $l, defined $insert ? $insert : 1); + myfill $_[0], $s, $l, defined $insert ? $insert : 1; } } @@ -66,14 +75,14 @@ sub try { push @b, $l2 if $l2 != $l; push @b, $l + 1; for my $b (@b) { + my $desc = "vshift $s, $l, $b, " . (defined $insert ? $insert : 'undef'); $v = $v0; rst $c; expect $c, $s, $l, $b, $left, $insert; $b = -$b unless $left; vshift $v, $s, $l => $b, $insert; - my $i = defined $insert ? $insert : 'undef'; - ok(myeq($v, 0, $c, 0, $n), "vshift $s, $l, $b, $i"); - is(length $v, length $c, "vshift $s, $l, $b, $i length"); + is length $v, length $c, "$desc: length"; + ok myeq($v, 0, $c, 0, $n), "$desc: bits"; } } }