4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bEncode\b/) {
6 print "1..0 # Skip: Encode was not built\n";
10 print "1..0 # Skip: EBCDIC\n";
13 unless (PerlIO::Layer->find('perlio')){
14 print "1..0 # Skip: PerlIO required\n";
17 if ($ENV{PERL_CORE_MINITEST}) {
18 print "1..0 # Skip: no dynamic loading on miniperl, no Encode\n";
28 # %mbchars = (encoding => { bytes => utf8, ... }, ...);
29 # * pack('C*') is expected to return bytes even if ${^ENCODING} is true.
32 pack('C*', 0x40) => pack('U*', 0x40), # COMMERCIAL AT
33 pack('C*', 0xA4, 0x40) => "\x{4E00}", # CJK-4E00
36 pack('C*', 0xB0, 0xA1) => "\x{4E9C}", # CJK-4E9C
37 pack('C*', 0x8F, 0xB0, 0xA1) => "\x{4E02}", # CJK-4E02
40 pack('C*', 0xA9) => "\x{FF69}", # halfwidth katakana small U
41 pack('C*', 0x82, 0xA9) => "\x{304B}", # hiragana KA
45 # 4 == @char; paired tests inside 3 nested loops,
46 # plus extra pair of tests in a loop, plus extra pair of tests.
47 plan tests => 2 * (4 ** 3 + 4 + 1) * (keys %mbchars);
49 for my $enc (sort keys %mbchars) {
50 local ${^ENCODING} = find_encoding($enc);
51 my @char = (sort(keys %{ $mbchars{$enc} }),
52 sort(values %{ $mbchars{$enc} }));
56 for my $start (@char) {
58 my $string = $start.$end;
59 my ($expect, $return);
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;
69 is (chomp ($string), $return);
70 is ($string, $expect); # "$enc \$/=$rs $start $end"
73 # chomp should not stringify references unless it decides to modify
78 is (ref($_), "ARRAY", "chomp ref (no modify)");
81 $/ = ")"; # the last char of something like "ARRAY(0x80ff6e4)"
84 ok (!ref($_), "chomp ref (modify)");