Upgrade to Encode 1.11, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / jperl.t
1 #
2 # $Id: jperl.t,v 1.11 2002/03/31 22:12:13 dankogai Exp dankogai $
3 #
4 # This script is written in euc-jp
5
6 use strict;
7 use Test::More tests => 15;
8 my $Debug = shift;
9
10 no encoding; # ensure
11 my $Enamae = "\xbe\xae\xbb\xf4\x20\xc3\xc6"; # euc-jp, with \x escapes
12 use encoding "euc-jp";
13
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"; 
18
19
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});
25 {
26     use bytes;
27     # converted to UTF-8 so 3*3+1
28     is(length($Namae),   10, q{bytes:length}); 
29     # 
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)); 
34 }
35 # let's test the scope as well.  Must be in utf8 realm
36 is(length($Namae), 4, q{utf8:length});
37
38 {
39     no encoding;
40     ok(! defined(${^ENCODING}), q{no encoding;});
41 }
42 # should've been isnt() but no scoping is suported -- yet
43 ok(! defined(${^ENCODING}), q{not scoped yet});
44 {
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});
50 }
51 ok(! defined(${^ENCODING}), q{out of black magic});
52 use bytes;
53 is (length($Namae), 10);
54 1;
55 __END__
56
57