From: Nicholas Clark Date: Fri, 23 Jan 2004 17:41:01 +0000 (+0000) Subject: Check the return values of chomp X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a61292d87a3ad96dcd4c6518e0d39ab9feb225d;p=p5sagit%2Fp5-mst-13.2.git Check the return values of chomp (more tricky than it may seem, as the return value is unicode) p4raw-id: //depot/perl@22198 --- diff --git a/t/uni/chomp.t b/t/uni/chomp.t index 1cb3d15..35eafdf 100644 --- a/t/uni/chomp.t +++ b/t/uni/chomp.t @@ -26,7 +26,8 @@ BEGIN { } use strict; -use Test::More tests => (4 * 4 * 4) * (3); # (@char ** 3) * (keys %mbchars) +# 2 * (@char ** 3) * (keys %mbchars) +use Test::More tests => 2 * (4 * 4 * 4) * (3); # %mbchars = (encoding => { bytes => utf8, ... }, ...); # * pack('C*') is expected to return bytes even if ${^ENCODING} is true. @@ -55,9 +56,18 @@ for my $enc (sort keys %mbchars) { for my $start (@char) { for my $end (@char) { my $string = $start.$end; - my $expect = $end eq $rs ? $start : $string; - chomp $string; - is($string, $expect); + my ($expect, $return); + if ($end eq $rs) { + $expect = $start; + # The answer will always be a length in utf8, even if the + # scalar was encoded with a different length + $return = length ($end . "\x{100}") - 1; + } else { + $expect = $string; + $return = 0; + } + is (chomp ($string), $return); + is ($string, $expect); # "$enc \$/=$rs $start $end" } } }