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