summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2021-07-07 07:08:54 -0600
committerKarl Williamson <khw@cpan.org>2021-07-18 08:40:24 -0700
commit2814f8a2e4e73d7a7e52ddb8d80e2f5d2175e3b8 (patch)
tree17212f29b94d42d8f52e1d97cd6468cf0650a334
parent8a0214ab98bbdd4da29dcb1e76877b3d24788e2e (diff)
downloadperl-2814f8a2e4e73d7a7e52ddb8d80e2f5d2175e3b8.tar.gz
Update op/length.t to use strict/modern 'is()' tests
Add strict and warnings, and modernize the part of the file that hann't already been modernized. This includes removing a few trailing blanks.
-rw-r--r--t/op/length.t103
1 files changed, 41 insertions, 62 deletions
diff --git a/t/op/length.t b/t/op/length.t
index 2cba924e31..2084633f49 100644
--- a/t/op/length.t
+++ b/t/op/length.t
@@ -1,4 +1,6 @@
#!./perl
+use warnings;
+use strict;
BEGIN {
chdir 't' if -d 't';
@@ -6,115 +8,98 @@ BEGIN {
set_up_inc('../lib');
}
-plan (tests => 41);
-
-print "not " unless length("") == 0;
-print "ok 1\n";
-
-print "not " unless length("abc") == 3;
-print "ok 2\n";
+plan (tests => 46);
+is(length(""), 0);
+is(length("abc"), 3);
$_ = "foobar";
-print "not " unless length() == 6;
-print "ok 3\n";
+is(length(), 6);
# Okay, so that wasn't very challenging. Let's go Unicode.
{
my $a = "\x{41}";
-
- print "not " unless length($a) == 1;
- print "ok 4\n";
- $test++;
+ is(length($a), 1);
use bytes;
- print "not " unless $a eq "\x41" && length($a) == 1;
- print "ok 5\n";
- $test++;
+ ok($a eq "\x41");
+ is(length($a), 1);
}
{
my $a = pack("U", 0xFF);
- print "not " unless length($a) == 1;
- print "ok 6\n";
- $test++;
+ is(length($a), 1);
use bytes;
if (ord('A') == 193)
{
printf "#%vx for 0xFF\n",$a;
- print "not " unless $a eq "\x8b\x73" && length($a) == 2;
+ ok($a eq "\x8b\x73");
+ is(length($a), 2);
}
else
{
- print "not " unless $a eq "\xc3\xbf" && length($a) == 2;
+ ok($a eq "\xc3\xbf");
+ is(length($a), 2);
}
- print "ok 7\n";
- $test++;
}
{
my $a = "\x{100}";
- print "not " unless length($a) == 1;
- print "ok 8\n";
- $test++;
+ is(length($a), 1);
use bytes;
if (ord('A') == 193)
{
printf "#%vx for 0x100\n",$a;
- print "not " unless $a eq "\x8c\x41" && length($a) == 2;
+ ok($a eq "\x8c\x41");
+ is(length($a), 2);
}
else
{
- print "not " unless $a eq "\xc4\x80" && length($a) == 2;
+ ok($a eq "\xc4\x80");
+ is(length($a), 2);
}
- print "ok 9\n";
- $test++;
}
{
my $a = "\x{100}\x{80}";
- print "not " unless length($a) == 2;
- print "ok 10\n";
- $test++;
+ is(length($a), 2);
use bytes;
if (ord('A') == 193)
{
printf "#%vx for 0x100 0x80\n",$a;
- print "not " unless $a eq "\x8c\x41\x8a\x67" && length($a) == 4;
+ ok($a eq "\x8c\x41\x8a\x67");
+ is(length($a), 4);
}
else
{
- print "not " unless $a eq "\xc4\x80\xc2\x80" && length($a) == 4;
+ ok($a eq "\xc4\x80\xc2\x80");
+ is(length($a), 4);
}
- print "ok 11\n";
- $test++;
}
{
my $a = "\x{80}\x{100}";
- print "not " unless length($a) == 2;
- print "ok 12\n";
- $test++;
+ is(length($a), 2);
use bytes;
if (ord('A') == 193)
{
printf "#%vx for 0x80 0x100\n",$a;
- print "not " unless $a eq "\x8a\x67\x8c\x41" && length($a) == 4;
+ ok($a eq "\x8a\x67\x8c\x41");
+ is(length($a), 4);
}
else
{
- print "not " unless $a eq "\xc2\x80\xc4\x80" && length($a) == 4;
+ ok($a eq "\xc2\x80\xc4\x80");
+ is(length($a), 4);
}
- print "ok 13\n";
- $test++;
}
# Now for Unicode with magical vtbls
@@ -124,37 +109,31 @@ print "ok 3\n";
my $a;
tie $a, 'Tie::StdScalar'; # makes $a magical
$a = "\x{263A}";
-
- print "not " unless length($a) == 1;
- print "ok 14\n";
- $test++;
+
+ is(length($a), 1);
use bytes;
- print "not " unless length($a) == 3;
- print "ok 15\n";
- $test++;
+ is(length($a), 3);
}
{
# Play around with Unicode strings,
# give a little workout to the UTF-8 length cache.
my $a = chr(256) x 100;
- print length $a == 100 ? "ok 16\n" : "not ok 16\n";
+ is(length $a, 100);
chop $a;
- print length $a == 99 ? "ok 17\n" : "not ok 17\n";
+ is(length $a, 99);
$a .= $a;
- print length $a == 198 ? "ok 18\n" : "not ok 18\n";
+ is(length $a, 198);
$a = chr(256) x 999;
- print length $a == 999 ? "ok 19\n" : "not ok 19\n";
+ is(length $a, 999);
substr($a, 0, 1) = '';
- print length $a == 998 ? "ok 20\n" : "not ok 20\n";
+ is(length $a, 998);
}
-curr_test(21);
-
require Tie::Scalar;
-$u = "ASCII";
+my $u = "ASCII";
tie $u, 'Tie::StdScalar', chr 256;
@@ -172,7 +151,7 @@ $SIG{__WARN__} = sub {
is(length(undef), undef, "Length of literal undef");
-my $u;
+undef $u;
is(length($u), undef, "Length of regular scalar");
@@ -199,7 +178,7 @@ my $uo = bless [], 'U';
}
my $ul = 3;
-is(($ul = length(undef)), undef,
+is(($ul = length(undef)), undef,
"Returned length of undef with result in TARG");
is($ul, undef, "Assigned length of undef with result in TARG");
@@ -215,7 +194,7 @@ $ul = 3;
is(($ul = length($uo)), 0,
"Returned length of overloaded undef with result in TARG");
like $w, qr/uninitialized/, 'uninit warning for stringifying as undef';
-}
+}
is($ul, 0, "Assigned length of overloaded undef with result in TARG");
{