summaryrefslogtreecommitdiff
path: root/t/uni/chomp.t
blob: 35060eeeb873b6c7e7fe9544a357479b14076e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!./perl -w

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    skip_all_without_perlio();
}

use strict;

# 6 == @char; paired tests inside 3 nested loops,
# plus extra pair of tests in a loop, plus extra pair of tests.
plan tests => 6 ** 3 * 2 + 6 * 2 + 2;

my @char = (pack('U*', 0x40), "\x{4E00}", "\x{4E9C}", "\x{4E02}",
           "\x{FF69}", "\x{304B}");

for my $rs (@char) {
	local $/ = $rs;
	for my $start (@char) {
	    for my $end (@char) {
		my $string = $start.$end;
		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"
	    }
	}
	# chomp should not stringify references unless it decides to modify
	# them
	$_ = [];
	my $got = chomp();
	is ($got, 0);
	is (ref($_), "ARRAY", "chomp ref (no modify)");
}

$/ = ")";  # the last char of something like "ARRAY(0x80ff6e4)"
my $got = chomp();
is ($got, 1);
ok (!ref($_), "chomp ref (modify)");