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