xref: /openbsd-src/gnu/usr.bin/perl/cpan/Encode/t/jperl.t (revision c90a81c56dcebd6a1b73fe4aff9b03385b8e63b3)
1#
2# $Id: jperl.t,v 2.2 2013/02/18 02:23:56 dankogai Exp $
3#
4# This script is written in euc-jp
5
6BEGIN {
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    $| = 1;
21}
22
23no utf8; # we have raw Japanese encodings here
24
25use strict;
26#use Test::More tests => 18;
27use Test::More tests => 15; # black magic tests commented out
28my $Debug = shift;
29
30no warnings "deprecated";
31no encoding; # ensure
32my $Enamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6"; # euc-jp, with \x escapes
33use encoding "euc-jp";
34
35my $Namae  = "���� ��";   # in Japanese, in euc-jp
36my $Name   = "Dan Kogai"; # in English
37# euc-jp in \x format but after the pragma.  But this one will be converted!
38my $Ynamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
39
40
41my $str = $Namae; $str =~ s/���� ��/Dan Kogai/o;
42is($str, $Name, q{regex});
43$str = $Namae; $str =~ s/$Namae/Dan Kogai/o;
44is($str, $Name, q{regex - with variable});
45is(length($Namae), 4, q{utf8:length});
46{
47    use bytes;
48    # converted to UTF-8 so 3*3+1
49    is(length($Namae),   10, q{bytes:length});
50    #
51    is(length($Enamae),   7, q{euc:length}); # 2*3+1
52    is ($Namae, $Ynamae,     q{literal conversions});
53    isnt($Enamae, $Ynamae,   q{before and after});
54    is($Enamae, Encode::encode('euc-jp', $Namae));
55}
56# let's test the scope as well.  Must be in utf8 realm
57is(length($Namae), 4, q{utf8:length});
58
59{
60    no encoding;
61    ok(! defined(${^ENCODING}), q{no encoding;});
62}
63# should've been isnt() but no scoping is suported -- yet
64ok(! defined(${^ENCODING}), q{not scoped yet});
65
66#
67# The following tests are commented out to accomodate
68# Inaba-San's patch to make tr/// work w/o eval qq{}
69#{
70#    # now let's try some real black magic!
71#    local(${^ENCODING}) = Encode::find_encoding("euc-jp");
72#    my $str = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
73#   is (length($str), 4, q{black magic:length});
74#   is ($str, $Enamae,   q{black magic:eq});
75#}
76#ok(! defined(${^ENCODING}), q{out of black magic});
77use bytes;
78is (length($Namae), 10);
79
80#
81# now something completely different!
82#
83{
84    use encoding "euc-jp", Filter=>1;
85    ok(1, "Filter on");
86    use utf8;
87    no strict 'vars'; # fools
88    # doesn't work w/ "my" as of this writing.
89    # because of  buggy strict.pm and utf8.pm
90    our $�� = 2;
91    #   ^^U+4eba, "human" in CJK ideograph
92    $��++; # a child is born
93    *people = \$��;
94    is ($people, 3, "Filter:utf8 identifier");
95    no encoding;
96    ok(1, "Filter off");
97}
98
991;
100__END__
101
102
103