2 if ($ENV{'PERL_CORE'}){
4 unshift @INC, '../lib';
6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
16 use Test::More tests => 778;
20 # The specification of GSM 03.38 is not awfully clear.
21 # (http://www.unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT)
22 # The various combinations of 0x00 and 0x1B as leading bytes
23 # are unclear, as is the semantics of those bytes as standalone
24 # or as final single bytes.
27 my $chk = Encode::LEAVE_SRC();
30 # see http://www.csoft.co.uk/sms/character_sets/gsm.htm
32 "\x{20ac}" => "\x1b\x65",
44 my %unesc_seq = reverse %esc_seq;
48 $_[0] =~ /[\x00-\x1f]/ ?
49 sprintf("\\x{%04X}", ord($_[0])) : encode_utf8($_[0]);
53 for my $c ( map { chr } 0 .. 127 ) {
54 my $u = $Encode::GSM0338::GSM2UNI{$c};
56 # default character set
57 is decode( "gsm0338", $c, $chk ), $u,
58 sprintf( "decode \\x%02X", ord($c) );
59 eval { decode( "gsm0338", $c . "\xff", $chk ) };
61 is encode( "gsm0338", $u, $chk ), $c, sprintf( "encode %s", eu($u) );
62 eval { encode( "gsm0338", $u . "\x{3000}", $chk ) };
67 is decode( "gsm0338", "\x00" . $c, $chk ), "\x00",
68 sprintf( '@@ =>: \x00+\x%02X', ord($c) );
71 is decode( "gsm0338", "\x00" . $c ), '@' . decode( "gsm0338", $c ),
72 sprintf( '@: decode \x00+\x%02X', ord($c) );
76 my $ecs = "\x1b" . $c;
77 if ( $unesc_seq{$ecs} ) {
78 is decode( "gsm0338", $ecs, $chk ), $unesc_seq{$ecs},
79 sprintf( "ESC: decode ESC+\\x%02X", ord($c) );
80 is encode( "gsm0338", $unesc_seq{$ecs}, $chk ), $ecs,
81 sprintf( "ESC: encode %s ", eu( $unesc_seq{$ecs} ) );
84 is decode( "gsm0338", $ecs, $chk ),
85 "\xA0" . decode( "gsm0338", $c ),
86 sprintf( "decode ESC+\\x%02X", ord($c) );
91 for my $c (map { chr } 0..127){
93 my $u = $Encode::GSM0338::GSM2UNI{$b};
95 $u ||= "\xA0" . $Encode::GSM0338::GSM2UNI{$c};
96 is decode("gsm0338", $b), $u, sprintf("decode ESC+\\x%02X", ord($c) );
101 ub t { is(decode("gsm0338", my $t = $_[0]), $_[1]) }
103 # t("\x00", "\x00"); # ???
113 t("\x00\x00", "\x00\x00"); # Maybe?
114 t("\x00\x1B", "\x40\xA0"); # Maybe?
115 t("\x00\x41", "\x40\x41");
117 # t("\x1B", "\x1B"); # ???
119 # Escape with no special second byte is just a NBSP.
120 t("\x1B\x41", "\xA0\x41");
122 t("\x1B\x00", "\xA0\x40"); # Maybe?
124 # Special escape characters.
125 t("\x1B\x0A", "\x0C");
126 t("\x1B\x14", "\x5E");
127 t("\x1B\x28", "\x7B");
128 t("\x1B\x29", "\x7D");
129 t("\x1B\x2F", "\x5C");
130 t("\x1B\x3C", "\x5B");
131 t("\x1B\x3D", "\x7E");
132 t("\x1B\x3E", "\x5D");
133 t("\x1B\x40", "\x7C");
134 t("\x1B\x40", "\x7C");
135 t("\x1B\x65", "\x{20AC}");