This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove workaround for distros needing dot in @INC
[perl5.git] / t / uni / chomp.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     require './test.pl';
6     skip_all_without_perlio();
7 }
8
9 use 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.
13 plan tests => 6 ** 3 * 2 + 6 * 2 + 2;
14
15 my @char = (pack('U*', 0x40), "\x{4E00}", "\x{4E9C}", "\x{4E02}",
16            "\x{FF69}", "\x{304B}");
17
18 for 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)"
46 my $got = chomp();
47 is ($got, 1);
48 ok (!ref($_), "chomp ref (modify)");
49