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