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