1#!./perl -w
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    skip_all_without_perlio();
7}
8
9use strict;
10
11# 6 == @char; paired tests inside 3 nested loops,
12# plus extra pair of tests in a loop, plus extra pair of tests.
13plan tests => 6 ** 3 * 2 + 6 * 2 + 2;
14
15my @char = (pack('U*', 0x40), "\x{4E00}", "\x{4E9C}", "\x{4E02}",
16           "\x{FF69}", "\x{304B}");
17
18for my $rs (@char) {
19	local $/ = $rs;
20	for my $start (@char) {
21	    for my $end (@char) {
22		my $string = $start.$end;
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"
35	    }
36	}
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)");
43}
44
45$/ = ")";  # the last char of something like "ARRAY(0x80ff6e4)"
46my $got = chomp();
47is ($got, 1);
48ok (!ref($_), "chomp ref (modify)");
49
50