do subname() is deprecated, so this test from perl 3 needs updating.
[p5sagit/p5-mst-13.2.git] / t / uni / chomp.t
CommitLineData
a6aa349d 1#!./perl -w
2
3BEGIN {
a6aa349d 4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
7 exit 0;
8 }
9 if (ord("A") == 193) {
10 print "1..0 # Skip: EBCDIC\n";
11 exit 0;
12 }
13 unless (PerlIO::Layer->find('perlio')){
14 print "1..0 # Skip: PerlIO required\n";
15 exit 0;
16 }
be8eafc6 17 if ($ENV{PERL_CORE_MINITEST}) {
18 print "1..0 # Skip: no dynamic loading on miniperl, no Encode\n";
a6aa349d 19 exit 0;
20 }
e4206093 21
22 require './test.pl';
a6aa349d 23}
24
25use strict;
e4206093 26use Encode;
a6aa349d 27
28# %mbchars = (encoding => { bytes => utf8, ... }, ...);
29# * pack('C*') is expected to return bytes even if ${^ENCODING} is true.
30our %mbchars = (
31 'big-5' => {
32 pack('C*', 0x40) => pack('U*', 0x40), # COMMERCIAL AT
33 pack('C*', 0xA4, 0x40) => "\x{4E00}", # CJK-4E00
34 },
35 'euc-jp' => {
36 pack('C*', 0xB0, 0xA1) => "\x{4E9C}", # CJK-4E9C
37 pack('C*', 0x8F, 0xB0, 0xA1) => "\x{4E02}", # CJK-4E02
38 },
39 'shift-jis' => {
40 pack('C*', 0xA9) => "\x{FF69}", # halfwidth katakana small U
41 pack('C*', 0x82, 0xA9) => "\x{304B}", # hiragana KA
42 },
43);
44
1858f5c3 45# 4 == @char; paired tests inside 3 nested loops,
46# plus extra pair of tests in a loop, plus extra pair of tests.
47plan tests => 2 * (4 ** 3 + 4 + 1) * (keys %mbchars);
48
a6aa349d 49for my $enc (sort keys %mbchars) {
50 local ${^ENCODING} = find_encoding($enc);
51 my @char = (sort(keys %{ $mbchars{$enc} }),
52 sort(values %{ $mbchars{$enc} }));
53
54 for my $rs (@char) {
55 local $/ = $rs;
56 for my $start (@char) {
57 for my $end (@char) {
58 my $string = $start.$end;
0a61292d 59 my ($expect, $return);
60 if ($end eq $rs) {
61 $expect = $start;
62 # The answer will always be a length in utf8, even if the
63 # scalar was encoded with a different length
64 $return = length ($end . "\x{100}") - 1;
65 } else {
66 $expect = $string;
67 $return = 0;
68 }
69 is (chomp ($string), $return);
70 is ($string, $expect); # "$enc \$/=$rs $start $end"
a6aa349d 71 }
72 }
1858f5c3 73 # chomp should not stringify references unless it decides to modify
74 # them
75 $_ = [];
76 my $got = chomp();
77 is ($got, 0);
78 is (ref($_), "ARRAY", "chomp ref (no modify)");
a6aa349d 79 }
1858f5c3 80
81 $/ = ")"; # the last char of something like "ARRAY(0x80ff6e4)"
82 my $got = chomp();
83 is ($got, 1);
84 ok (!ref($_), "chomp ref (modify)");
a6aa349d 85}