X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fchop.t;h=bacc439676a26b594a1ce52c0fe9bf7e9a086e60;hb=e24631be6ac297b562086a055de17c5bd4247797;hp=abb8aba7325c6ea39ef980b72db5d19899019744;hpb=991e6d419e6cb68835dda77416b60c341a13a26e;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/chop.t b/t/op/chop.t index abb8aba..bacc439 100755 --- a/t/op/chop.t +++ b/t/op/chop.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 47; +plan tests => 133; $_ = 'abc'; $c = do foo(); @@ -172,3 +172,53 @@ foreach (keys %chop) { is ($_, $chop{$key}, "chop hash key"); } } + +# chop and chomp can't be lvalues +eval 'chop($x) = 1;'; +ok($@ =~ /Can\'t modify.*chop.*in.*assignment/); +eval 'chomp($x) = 1;'; +ok($@ =~ /Can\'t modify.*chom?p.*in.*assignment/); +eval 'chop($x, $y) = (1, 2);'; +ok($@ =~ /Can\'t modify.*chop.*in.*assignment/); +eval 'chomp($x, $y) = (1, 2);'; +ok($@ =~ /Can\'t modify.*chom?p.*in.*assignment/); + +my @chars = ("N", "\xd3", substr ("\xd4\x{100}", 0, 1), chr 1296); +foreach my $start (@chars) { + foreach my $end (@chars) { + local $/ = $end; + my $message = "start=" . ord ($start) . " end=" . ord $end; + my $string = $start . $end; + is (chomp ($string), 1, "$message [returns 1]"); + is ($string, $start, $message); + + my $end_utf8 = $end; + utf8::encode ($end_utf8); + next if $end_utf8 eq $end; + + # $end ne $end_utf8, so these should not chomp. + $string = $start . $end_utf8; + my $chomped = $string; + is (chomp ($chomped), 0, "$message (end as bytes) [returns 0]"); + is ($chomped, $string, "$message (end as bytes)"); + + $/ = $end_utf8; + $string = $start . $end; + $chomped = $string; + 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); +}