xref: /openbsd-src/gnu/usr.bin/perl/cpan/Encode/t/jperl.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1b39c5158Smillert#
2*3d61058aSafresh1# $Id: jperl.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $
3b39c5158Smillert#
4b39c5158Smillert# This script is written in euc-jp
5b39c5158Smillert
6b39c5158SmillertBEGIN {
7*3d61058aSafresh1    require Config; Config->import();
8b39c5158Smillert    if ($Config{'extensions'} !~ /\bEncode\b/) {
9b39c5158Smillert      print "1..0 # Skip: Encode was not built\n";
10b39c5158Smillert      exit 0;
11b39c5158Smillert    }
12b39c5158Smillert    unless (find PerlIO::Layer 'perlio') {
13b39c5158Smillert    print "1..0 # Skip: PerlIO was not built\n";
14b39c5158Smillert    exit 0;
15b39c5158Smillert    }
16b39c5158Smillert    if (ord("A") == 193) {
17b39c5158Smillert    print "1..0 # Skip: EBCDIC\n";
18b39c5158Smillert    exit 0;
19b39c5158Smillert    }
209f11ffb7Safresh1    if ($] >= 5.025 and !$Config{usecperl}) {
21eac174f2Safresh1    print "1..0 # Skip: encoding pragma not supported in Perl 5.25 or later\n";
229f11ffb7Safresh1    exit(0);
239f11ffb7Safresh1    }
24b39c5158Smillert    $| = 1;
25b39c5158Smillert}
26b39c5158Smillert
27b39c5158Smillertno utf8; # we have raw Japanese encodings here
28b39c5158Smillert
29b39c5158Smillertuse strict;
30b39c5158Smillert#use Test::More tests => 18;
31b39c5158Smillertuse Test::More tests => 15; # black magic tests commented out
32b39c5158Smillertmy $Debug = shift;
33b39c5158Smillert
34e9ce3842Safresh1no warnings "deprecated";
35b39c5158Smillertno encoding; # ensure
36b39c5158Smillertmy $Enamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6"; # euc-jp, with \x escapes
37b39c5158Smillertuse encoding "euc-jp";
38b39c5158Smillert
39b39c5158Smillertmy $Namae  = "���� ��";   # in Japanese, in euc-jp
40b39c5158Smillertmy $Name   = "Dan Kogai"; # in English
41b39c5158Smillert# euc-jp in \x format but after the pragma.  But this one will be converted!
42b39c5158Smillertmy $Ynamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
43b39c5158Smillert
44b39c5158Smillert
45b39c5158Smillertmy $str = $Namae; $str =~ s/���� ��/Dan Kogai/o;
46b39c5158Smillertis($str, $Name, q{regex});
47b39c5158Smillert$str = $Namae; $str =~ s/$Namae/Dan Kogai/o;
48b39c5158Smillertis($str, $Name, q{regex - with variable});
49b39c5158Smillertis(length($Namae), 4, q{utf8:length});
50b39c5158Smillert{
51b39c5158Smillert    use bytes;
52b39c5158Smillert    # converted to UTF-8 so 3*3+1
53b39c5158Smillert    is(length($Namae),   10, q{bytes:length});
54b39c5158Smillert    #
55b39c5158Smillert    is(length($Enamae),   7, q{euc:length}); # 2*3+1
56b39c5158Smillert    is ($Namae, $Ynamae,     q{literal conversions});
57b39c5158Smillert    isnt($Enamae, $Ynamae,   q{before and after});
58b39c5158Smillert    is($Enamae, Encode::encode('euc-jp', $Namae));
59b39c5158Smillert}
60b39c5158Smillert# let's test the scope as well.  Must be in utf8 realm
61b39c5158Smillertis(length($Namae), 4, q{utf8:length});
62b39c5158Smillert
63b39c5158Smillert{
64b39c5158Smillert    no encoding;
65b39c5158Smillert    ok(! defined(${^ENCODING}), q{no encoding;});
66b39c5158Smillert}
67b39c5158Smillert# should've been isnt() but no scoping is suported -- yet
68b39c5158Smillertok(! defined(${^ENCODING}), q{not scoped yet});
69b39c5158Smillert
70b39c5158Smillert#
71b39c5158Smillert# The following tests are commented out to accomodate
72b39c5158Smillert# Inaba-San's patch to make tr/// work w/o eval qq{}
73b39c5158Smillert#{
74b39c5158Smillert#    # now let's try some real black magic!
75b39c5158Smillert#    local(${^ENCODING}) = Encode::find_encoding("euc-jp");
76b39c5158Smillert#    my $str = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
77b39c5158Smillert#   is (length($str), 4, q{black magic:length});
78b39c5158Smillert#   is ($str, $Enamae,   q{black magic:eq});
79b39c5158Smillert#}
80b39c5158Smillert#ok(! defined(${^ENCODING}), q{out of black magic});
81b39c5158Smillertuse bytes;
82b39c5158Smillertis (length($Namae), 10);
83b39c5158Smillert
84b39c5158Smillert#
85b39c5158Smillert# now something completely different!
86b39c5158Smillert#
87b39c5158Smillert{
88b39c5158Smillert    use encoding "euc-jp", Filter=>1;
89b39c5158Smillert    ok(1, "Filter on");
90b39c5158Smillert    use utf8;
91b39c5158Smillert    no strict 'vars'; # fools
92b39c5158Smillert    # doesn't work w/ "my" as of this writing.
93b39c5158Smillert    # because of  buggy strict.pm and utf8.pm
94b39c5158Smillert    our $�� = 2;
95b39c5158Smillert    #   ^^U+4eba, "human" in CJK ideograph
96b39c5158Smillert    $��++; # a child is born
97b39c5158Smillert    *people = \$��;
98b39c5158Smillert    is ($people, 3, "Filter:utf8 identifier");
99b39c5158Smillert    no encoding;
100b39c5158Smillert    ok(1, "Filter off");
101b39c5158Smillert}
102b39c5158Smillert
103b39c5158Smillert1;
104b39c5158Smillert__END__
105b39c5158Smillert
106b39c5158Smillert
107