require './test.pl';
}
-plan tests => 91;
+plan tests => 137;
$_ = 'abc';
$c = do foo();
local $/ = $end;
my $message = "start=" . ord ($start) . " end=" . ord $end;
my $string = $start . $end;
- chomp $string;
+ is (chomp ($string), 1, "$message [returns 1]");
is ($string, $start, $message);
my $end_utf8 = $end;
# $end ne $end_utf8, so these should not chomp.
$string = $start . $end_utf8;
my $chomped = $string;
- chomp $chomped;
+ is (chomp ($chomped), 0, "$message (end as bytes) [returns 0]");
is ($chomped, $string, "$message (end as bytes)");
$/ = $end_utf8;
$string = $start . $end;
$chomped = $string;
- chomp $chomped;
+ is (chomp ($chomped), 0, "$message (\$/ as bytes) [returns 0]");
is ($chomped, $string, "$message (\$/ as bytes)");
}
}
+
+{
+ # returns length in characters, but not in bytes.
+ $/ = "\x{100}";
+ $a = "A$/";
+ $b = chomp $a;
+ is ($b, 1);
+
+ $/ = "\x{100}\x{101}";
+ $a = "A$/";
+ $b = chomp $a;
+ is ($b, 2);
+}
+
+{
+ # [perl #36569] chop fails on decoded string with trailing nul
+ my $asc = "perl\0";
+ my $utf = "perl".pack('U',0); # marked as utf8
+ is(chop($asc), "\0", "chopping ascii NUL");
+ is(chop($utf), "\0", "chopping utf8 NUL");
+ is($asc, "perl", "chopped ascii NUL");
+ is($utf, "perl", "chopped utf8 NUL");
+}