Commit | Line | Data |
---|---|---|
a6aa349d TS |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
b5efbd1f | 4 | chdir 't' if -d 't'; |
e4206093 | 5 | require './test.pl'; |
b5b7b9ad | 6 | skip_all_without_perlio(); |
a6aa349d TS |
7 | } |
8 | ||
9 | use strict; | |
a6aa349d | 10 | |
a15a3d9b | 11 | # 6 == @char; paired tests inside 3 nested loops, |
1858f5c3 | 12 | # plus extra pair of tests in a loop, plus extra pair of tests. |
a15a3d9b | 13 | plan tests => 6 ** 3 * 2 + 6 * 2 + 2; |
1858f5c3 | 14 | |
a15a3d9b FC |
15 | my @char = (pack('U*', 0x40), "\x{4E00}", "\x{4E9C}", "\x{4E02}", |
16 | "\x{FF69}", "\x{304B}"); | |
a6aa349d | 17 | |
a15a3d9b | 18 | for my $rs (@char) { |
a6aa349d TS |
19 | local $/ = $rs; |
20 | for my $start (@char) { | |
21 | for my $end (@char) { | |
22 | my $string = $start.$end; | |
0a61292d NC |
23 | my ($expect, $return); |
24 | if ($end eq $rs) { | |
25 | $expect = $start; | |
26 | # The answer will always be a length in utf8, even if the | |
27 | # scalar was encoded with a different length | |
28 | $return = length ($end . "\x{100}") - 1; | |
29 | } else { | |
30 | $expect = $string; | |
31 | $return = 0; | |
32 | } | |
33 | is (chomp ($string), $return); | |
34 | is ($string, $expect); # "$enc \$/=$rs $start $end" | |
a6aa349d TS |
35 | } |
36 | } | |
1858f5c3 NC |
37 | # chomp should not stringify references unless it decides to modify |
38 | # them | |
39 | $_ = []; | |
40 | my $got = chomp(); | |
41 | is ($got, 0); | |
42 | is (ref($_), "ARRAY", "chomp ref (no modify)"); | |
a6aa349d | 43 | } |
a15a3d9b FC |
44 | |
45 | $/ = ")"; # the last char of something like "ARRAY(0x80ff6e4)" | |
46 | my $got = chomp(); | |
47 | is ($got, 1); | |
48 | ok (!ref($_), "chomp ref (modify)"); | |
49 |