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