2 # $Id: jperl.t,v 1.11 2002/03/31 22:12:13 dankogai Exp dankogai $
4 # This script is written in euc-jp
7 use Test::More tests => 15;
11 my $Enamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6"; # euc-jp, with \x escapes
12 use encoding "euc-jp";
14 my $Namae = "¾®»ô ÃÆ"; # in Japanese, in euc-jp
15 my $Name = "Dan Kogai"; # in English
16 # euc-jp in \x format but after the pragma. But this one will be converted!
17 my $Ynamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
20 my $str = $Namae; $str =~ s/¾®»ô ÃÆ/Dan Kogai/o;
21 is($str, $Name, q{regex});
22 $str = $Namae; $str =~ s/$Namae/Dan Kogai/o;
23 is($str, $Name, q{regex - with variable});
24 is(length($Namae), 4, q{utf8:length});
27 # converted to UTF-8 so 3*3+1
28 is(length($Namae), 10, q{bytes:length});
30 is(length($Enamae), 7, q{euc:length}); # 2*3+1
31 is ($Namae, $Ynamae, q{literal conversions});
32 isnt($Enamae, $Ynamae, q{before and after});
33 is($Enamae, Encode::encode('euc-jp', $Namae));
35 # let's test the scope as well. Must be in utf8 realm
36 is(length($Namae), 4, q{utf8:length});
40 ok(! defined(${^ENCODING}), q{no encoding;});
42 # should've been isnt() but no scoping is suported -- yet
43 ok(! defined(${^ENCODING}), q{not scoped yet});
45 # now let's try some real black magic!
46 local(${^ENCODING}) = Encode::find_encoding("euc-jp");
47 my $str = "\xbe\xae\xbb\xf4\x20\xc3\xc6";
48 is (length($str), 4, q{black magic:length});
49 is ($str, $Enamae, q{black magic:eq});
51 ok(! defined(${^ENCODING}), q{out of black magic});
53 is (length($Namae), 10);