]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blobdiff - t/10-veq-pp.t
Improve argument checking
[perl/modules/Scalar-Vec-Util.git] / t / 10-veq-pp.t
index ffd721a76ce95f665df24da863e56f74369f6f17..509fd98f3cba1989c96a62681e9f0e1535340961 100644 (file)
@@ -5,25 +5,24 @@ use warnings;
 
 use Test::More 'no_plan';
 
-use Scalar::Vec::Util qw/SVU_SIZE/;
-
-eval { Scalar::Vec::Util::veq_pp(undef, 0, my $y, 0, 0) };
-like($@, qr/Invalid\s+argument/, 'first argument undef croaks');
-eval { Scalar::Vec::Util::veq_pp(my $x, undef, my $y, 0, 0) };
-like($@, qr/Invalid\s+argument/, 'second argument undef croaks');
-eval { Scalar::Vec::Util::veq_pp(my $x, 0, undef, 0, 0) };
-like($@, qr/Invalid\s+argument/, 'third argument undef croaks');
-eval { Scalar::Vec::Util::veq_pp(my $x, 0, my $y, undef, 0) };
-like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks');
-eval { Scalar::Vec::Util::veq_pp(my $x, 0, my $y, 0, undef) };
-like($@, qr/Invalid\s+argument/, 'fifth argument undef croaks');
-
-my $p = SVU_SIZE;
-$p = 8 if $p < 8;
+use Scalar::Vec::Util;
+
+for ([ 1, 'offset', -1 ], [ 3, 'offset', '-1' ], [ 4, 'length', -1 ]) {
+ my @args  = ('1') x 5;
+ $args[$_->[0]] = $_->[2];
+ eval { &Scalar::Vec::Util::veq_pp(@args) }; my $line = __LINE__;
+ like $@, qr/^Invalid\s+negative\s+$_->[1]\s+at\s+\Q$0\E\s+line\s+$line/;
+}
+
+my $p = 8;
 my $n = 3 * $p;
 my $q = 1;
 
-*myfill = *Scalar::Vec::Util::vfill_pp;
+sub myfill {
+ (undef, my $s, my $l, my $x) = @_;
+ $x = 1 if $x;
+ vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+}
 
 sub rst { myfill($_[0], 0, $n, 0) }