Cygwin doesn't like initing the $0 mutex in perl_construct()
[p5sagit/p5-mst-13.2.git] / lib / charnames.t
1 #!./perl
2
3 my @WARN;
4
5 BEGIN {
6     unless(grep /blib/, @INC) {
7         chdir 't' if -d 't';
8         @INC = '../lib';
9         require './test.pl';
10     }
11     $SIG{__WARN__} = sub { push @WARN, @_ };
12 }
13
14 $| = 1;
15
16 print "1..73\n";
17
18 use charnames ':full';
19
20 print "not " unless "Here\N{EXCLAMATION MARK}?" eq "Here!?";
21 print "ok 1\n";
22
23 {
24   use bytes;                    # TEST -utf8 can switch utf8 on
25
26   print "# \$res=$res \$\@='$@'\nnot "
27     if $res = eval <<'EOE'
28 use charnames ":full";
29 "Here: \N{CYRILLIC SMALL LETTER BE}!";
30 1
31 EOE
32       or $@ !~ /above 0xFF/;
33   print "ok 2\n";
34   # print "# \$res=$res \$\@='$@'\n";
35
36   print "# \$res=$res \$\@='$@'\nnot "
37     if $res = eval <<'EOE'
38 use charnames 'cyrillic';
39 "Here: \N{Be}!";
40 1
41 EOE
42       or $@ !~ /CYRILLIC CAPITAL LETTER BE.*above 0xFF/;
43   print "ok 3\n";
44 }
45
46 # If octal representation of unicode char is \0xyzt, then the utf8 is \3xy\2zt
47 if (ord('A') == 65) { # as on ASCII or UTF-8 machines
48     $encoded_be = "\320\261";
49     $encoded_alpha = "\316\261";
50     $encoded_bet = "\327\221";
51     $encoded_deseng = "\360\220\221\215";
52 }
53 else { # EBCDIC where UTF-EBCDIC may be used (this may be 1047 specific since
54        # UTF-EBCDIC is codepage specific)
55     $encoded_be = "\270\102\130";
56     $encoded_alpha = "\264\130";
57     $encoded_bet = "\270\125\130";
58     $encoded_deseng = "\336\102\103\124";
59 }
60
61 sub to_bytes {
62     pack"a*", shift;
63 }
64
65 {
66   use charnames ':full';
67
68   print "not " unless to_bytes("\N{CYRILLIC SMALL LETTER BE}") eq $encoded_be;
69   print "ok 4\n";
70
71   use charnames qw(cyrillic greek :short);
72
73   print "not " unless to_bytes("\N{be},\N{alpha},\N{hebrew:bet}")
74     eq "$encoded_be,$encoded_alpha,$encoded_bet";
75   print "ok 5\n";
76 }
77
78 {
79     use charnames ':full';
80     print "not " unless "\x{263a}" eq "\N{WHITE SMILING FACE}";
81     print "ok 6\n";
82     print "not " unless length("\x{263a}") == 1;
83     print "ok 7\n";
84     print "not " unless length("\N{WHITE SMILING FACE}") == 1;
85     print "ok 8\n";
86     print "not " unless sprintf("%vx", "\x{263a}") eq "263a";
87     print "ok 9\n";
88     print "not " unless sprintf("%vx", "\N{WHITE SMILING FACE}") eq "263a";
89     print "ok 10\n";
90     print "not " unless sprintf("%vx", "\xFF\N{WHITE SMILING FACE}") eq "ff.263a";
91     print "ok 11\n";
92     print "not " unless sprintf("%vx", "\x{ff}\N{WHITE SMILING FACE}") eq "ff.263a";
93     print "ok 12\n";
94 }
95
96 {
97    use charnames qw(:full);
98    use utf8;
99
100     my $x = "\x{221b}";
101     my $named = "\N{CUBE ROOT}";
102
103     print "not " unless ord($x) == ord($named);
104     print "ok 13\n";
105 }
106
107 {
108    use charnames qw(:full);
109    use utf8;
110    print "not " unless "\x{100}\N{CENT SIGN}" eq "\x{100}"."\N{CENT SIGN}";
111    print "ok 14\n";
112 }
113
114 {
115   use charnames ':full';
116
117   print "not "
118       unless to_bytes("\N{DESERET SMALL LETTER ENG}") eq $encoded_deseng;
119   print "ok 15\n";
120 }
121
122 {
123   # 20001114.001
124
125   no utf8; # naked Latin-1
126
127   if (ord("Ä") == 0xc4) { # Try to do this only on Latin-1.
128       use charnames ':full';
129       my $text = "\N{LATIN CAPITAL LETTER A WITH DIAERESIS}";
130       print "not " unless $text eq "\xc4" && ord($text) == 0xc4;
131       print "ok 16\n";
132   } else {
133       print "ok 16 # Skip: not Latin-1\n";
134   }
135 }
136
137 {
138     print "not " unless charnames::viacode(0x1234) eq "ETHIOPIC SYLLABLE SEE";
139     print "ok 17\n";
140
141     # Unused Hebrew.
142     print "not " if defined charnames::viacode(0x0590);
143     print "ok 18\n";
144 }
145
146 {
147     print "not " unless
148         sprintf("%04X", charnames::vianame("GOTHIC LETTER AHSA")) eq "10330";
149     print "ok 19\n";
150
151     print "not " if
152         defined charnames::vianame("NONE SUCH");
153     print "ok 20\n";
154 }
155
156 {
157     # check that caching at least hasn't broken anything
158
159     print "not " unless charnames::viacode(0x1234) eq "ETHIOPIC SYLLABLE SEE";
160     print "ok 21\n";
161
162     print "not " unless
163         sprintf("%04X", charnames::vianame("GOTHIC LETTER AHSA")) eq "10330";
164     print "ok 22\n";
165
166 }
167
168 print "not " unless "\N{CHARACTER TABULATION}" eq "\t";
169 print "ok 23\n";
170
171 print "not " unless "\N{ESCAPE}" eq "\e";
172 print "ok 24\n";
173
174 print "not " unless "\N{NULL}" eq "\c@";
175 print "ok 25\n";
176
177 if ($^O eq 'MacOS')
178 {
179         print "not " unless "\N{CARRIAGE RETURN (CR)}" eq "\n";
180         print "ok 26\n";
181
182         print "not " unless "\N{CARRIAGE RETURN}" eq "\n";
183         print "ok 27\n";
184
185         print "not " unless "\N{CR}" eq "\n";
186         print "ok 28\n";
187 }
188 else
189 {
190         print "not " unless "\N{LINE FEED (LF)}" eq "\n";
191         print "ok 26\n";
192
193         print "not " unless "\N{LINE FEED}" eq "\n";
194         print "ok 27\n";
195
196         print "not " unless "\N{LF}" eq "\n";
197         print "ok 28\n";
198 }
199
200 my $nel = ord("A") == 193 ? qr/^(?:\x15|\x25)$/ : qr/^\x85$/;
201
202 print "not " unless "\N{NEXT LINE (NEL)}" =~ $nel;
203 print "ok 29\n";
204
205 print "not " unless "\N{NEXT LINE}" =~ $nel;
206 print "ok 30\n";
207
208 print "not " unless "\N{NEL}" =~ $nel;
209 print "ok 31\n";
210
211 print "not " unless "\N{BYTE ORDER MARK}" eq chr(0xFEFF);
212 print "ok 32\n";
213
214 print "not " unless "\N{BOM}" eq chr(0xFEFF);
215 print "ok 33\n";
216
217 {
218     use warnings 'deprecated';
219
220     print "not " unless "\N{HORIZONTAL TABULATION}" eq "\t";
221     print "ok 34\n";
222
223     print "not " unless grep { /"HORIZONTAL TABULATION" is deprecated/ } @WARN;
224     print "ok 35\n";
225
226     no warnings 'deprecated';
227
228     print "not " unless "\N{VERTICAL TABULATION}" eq "\013";
229     print "ok 36\n";
230
231     print "not " if grep { /"VERTICAL TABULATION" is deprecated/ } @WARN;
232     print "ok 37\n";
233 }
234
235 print "not " unless charnames::viacode(0xFEFF) eq "ZERO WIDTH NO-BREAK SPACE";
236 print "ok 38\n";
237
238 {
239     use warnings;
240     print "not " unless ord("\N{BOM}") == 0xFEFF;
241     print "ok 39\n";
242 }
243
244 print "not " unless ord("\N{ZWNJ}") == 0x200C;
245 print "ok 40\n";
246
247 print "not " unless ord("\N{ZWJ}") == 0x200D;
248 print "ok 41\n";
249
250 print "not " unless "\N{U+263A}" eq "\N{WHITE SMILING FACE}";
251 print "ok 42\n";
252
253 {
254     print "not " unless
255         0x3093 == charnames::vianame("HIRAGANA LETTER N");
256     print "ok 43\n";
257
258     print "not " unless
259         0x0397 == charnames::vianame("GREEK CAPITAL LETTER ETA");
260     print "ok 44\n";
261 }
262
263 print "not " if defined charnames::viacode(0x110000);
264 print "ok 45\n";
265
266 print "not " if grep { /you asked for U+110000/ } @WARN;
267 print "ok 46\n";
268
269
270 # ---- Alias extensions
271
272 my $tmpfile = "tmp0000";
273 my $alifile = "../lib/unicore/xyzzy_alias.pl";
274 my $i = 0;
275 1 while -e ++$tmpfile;
276 END { if ($tmpfile) { 1 while unlink $tmpfile; } }
277
278 my @prgs;
279 {   local $/ = undef;
280     @prgs = split "\n########\n", <DATA>;
281     }
282
283 my $i = 46;
284 for (@prgs) {
285     my ($code, $exp) = ((split m/\nEXPECT\n/), '$');
286     my ($prog, $fil) = ((split m/\nFILE\n/, $code), "");
287     open my $tmp, "> $tmpfile" or die "Could not open $tmpfile: $!";
288     print $tmp $prog, "\n";
289     close $tmp or die "Could not close $tmpfile: $!";
290     if ($fil) {
291         $fil .= "\n";
292         open my $ali, "> $alifile" or die "Could not open $alifile: $!";
293         print $ali $fil;
294         close $ali or die "Could not close $alifile: $!";
295         }
296     my $res = runperl( switches => $switch, 
297                        progfile => $tmpfile,
298                        stderr => 1 );
299     my $status = $?;
300     $res =~ s/[\r\n]+$//;
301     $res =~ s/tmp\d+/-/g;                       # fake $prog from STDIN
302     $res =~ s/\n%[A-Z]+-[SIWEF]-.*$//           # clip off DCL status msg
303         if $^O eq "VMS";
304     $exp =~ s/[\r\n]+$//;
305     if ($^O eq "MacOS") {
306         $exp =~ s{(\./)?abc\.pm}{:abc.pm}g;
307         $exp =~ s{./abc}        {:abc}g;
308         }
309     my $pfx = ($res =~ s/^PREFIX\n//);
310     my $rexp = qr{^$exp};
311     if ($res =~ s/^SKIPPED\n//) {
312         print "$results\n";
313         }
314     elsif (($pfx and $res !~ /^\Q$expected/) or
315           (!$pfx and $res !~ $rexp)) {
316         print STDERR
317             "PROG:\n$prog\n",
318             "FILE:\n$fil",
319             "EXPECTED:\n$exp\n",
320             "GOT:\n$res\n";
321         print "not ";
322         }
323     print "ok ", ++$i, "\n";
324     1 while unlink $tmpfile;
325     $fil or next;
326     1 while unlink $alifile;
327     }
328
329 __END__
330 # unsupported pragma
331 use charnames ":scoobydoo";
332 "Here: \N{e_ACUTE}!\n";
333 EXPECT
334 unsupported special ':scoobydoo' in charnames at
335 ########
336 # wrong type of alias (missing colon)
337 use charnames "alias";
338 "Here: \N{e_ACUTE}!\n";
339 EXPECT
340 Unknown charname 'e_ACUTE' at
341 ########
342 # alias without an argument
343 use charnames ":alias";
344 "Here: \N{e_ACUTE}!\n";
345 EXPECT
346 :alias needs an argument in charnames at
347 ########
348 # reversed sequence
349 use charnames ":alias" => ":full";
350 "Here: \N{e_ACUTE}!\n";
351 EXPECT
352 :alias cannot use existing pragma :full \(reversed order\?\) at
353 ########
354 # alias with hashref but no :full
355 use charnames ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
356 "Here: \N{e_ACUTE}!\n";
357 EXPECT
358 Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
359 ########
360 # alias with hashref but with :short
361 use charnames ":short", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
362 "Here: \N{e_ACUTE}!\n";
363 EXPECT
364 Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
365 ########
366 # alias with hashref to :full OK
367 use charnames ":full", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
368 "Here: \N{e_ACUTE}!\n";
369 EXPECT
370 $
371 ########
372 # alias with hashref to :short but using :full
373 use charnames ":full", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE" };
374 "Here: \N{e_ACUTE}!\n";
375 EXPECT
376 Unknown charname 'LATIN:e WITH ACUTE' at
377 ########
378 # alias with hashref to :short OK
379 use charnames ":short", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE" };
380 "Here: \N{e_ACUTE}!\n";
381 EXPECT
382 $
383 ########
384 # alias with bad hashref
385 use charnames ":short", ":alias" => "e_ACUTE";
386 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
387 EXPECT
388 unicore/e_ACUTE_alias.pl cannot be used as alias file for charnames at
389 ########
390 # alias with arrayref
391 use charnames ":short", ":alias" => [ e_ACUTE => "LATIN:e WITH ACUTE" ];
392 "Here: \N{e_ACUTE}!\n";
393 EXPECT
394 Only HASH reference supported as argument to :alias at
395 ########
396 # alias with bad hashref
397 use charnames ":short", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE", "a_ACUTE" };
398 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
399 EXPECT
400 Use of uninitialized value in string eq at
401 ########
402 # alias with hashref two aliases
403 use charnames ":short", ":alias" => {
404     e_ACUTE => "LATIN:e WITH ACUTE",
405     a_ACUTE => "",
406     };
407 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
408 EXPECT
409 Unknown charname '' at
410 ########
411 # alias with hashref two aliases
412 use charnames ":short", ":alias" => {
413     e_ACUTE => "LATIN:e WITH ACUTE",
414     a_ACUTE => "LATIN:a WITH ACUTE",
415     };
416 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
417 EXPECT
418 $
419 ########
420 # alias with hashref using mixed aliasses
421 use charnames ":short", ":alias" => {
422     e_ACUTE => "LATIN:e WITH ACUTE",
423     a_ACUTE => "LATIN SMALL LETTER A WITH ACUT",
424     };
425 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
426 EXPECT
427 Unknown charname 'LATIN SMALL LETTER A WITH ACUT' at
428 ########
429 # alias with hashref using mixed aliasses
430 use charnames ":short", ":alias" => {
431     e_ACUTE => "LATIN:e WITH ACUTE",
432     a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
433     };
434 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
435 EXPECT
436 Unknown charname 'LATIN SMALL LETTER A WITH ACUTE' at
437 ########
438 # alias with hashref using mixed aliasses
439 use charnames ":full", ":alias" => {
440     e_ACUTE => "LATIN:e WITH ACUTE",
441     a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
442     };
443 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
444 EXPECT
445 Unknown charname 'LATIN:e WITH ACUTE' at
446 ########
447 # alias with nonexisting file
448 use charnames ":full", ":alias" => "xyzzy";
449 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
450 EXPECT
451 unicore/xyzzy_alias.pl cannot be used as alias file for charnames at
452 ########
453 # alias with bad file name
454 use charnames ":full", ":alias" => "xy 7-";
455 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
456 EXPECT
457 Charnames alias files can only have identifier characters at
458 ########
459 # alias with non_absolute (existing) file name (which it should /not/ use)
460 use charnames ":full", ":alias" => "perl";
461 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
462 EXPECT
463 unicore/perl_alias.pl cannot be used as alias file for charnames at
464 ########
465 # alias with bad file
466 use charnames ":full", ":alias" => "xyzzy";
467 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
468 FILE
469 #!perl
470 0;
471 EXPECT
472 unicore/xyzzy_alias.pl did not return a \(valid\) list of alias pairs at
473 ########
474 # alias with file with empty list
475 use charnames ":full", ":alias" => "xyzzy";
476 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
477 FILE
478 #!perl
479 ();
480 EXPECT
481 Unknown charname 'e_ACUTE' at
482 ########
483 # alias with file OK but file has :short aliasses
484 use charnames ":full", ":alias" => "xyzzy";
485 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
486 FILE
487 #!perl
488 (   e_ACUTE => "LATIN:e WITH ACUTE",
489     a_ACUTE => "LATIN:a WITH ACUTE",
490     );
491 EXPECT
492 Unknown charname 'LATIN:e WITH ACUTE' at
493 ########
494 # alias with :short and file OK
495 use charnames ":short", ":alias" => "xyzzy";
496 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
497 FILE
498 #!perl
499 (   e_ACUTE => "LATIN:e WITH ACUTE",
500     a_ACUTE => "LATIN:a WITH ACUTE",
501     );
502 EXPECT
503 $
504 ########
505 # alias with :short and file OK has :long aliasses
506 use charnames ":short", ":alias" => "xyzzy";
507 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
508 FILE
509 #!perl
510 (   e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
511     a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
512     );
513 EXPECT
514 Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
515 ########
516 # alias with file implicit :full but file has :short aliasses
517 use charnames ":alias" => ":xyzzy";
518 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
519 FILE
520 #!perl
521 (   e_ACUTE => "LATIN:e WITH ACUTE",
522     a_ACUTE => "LATIN:a WITH ACUTE",
523     );
524 EXPECT
525 Unknown charname 'LATIN:e WITH ACUTE' at
526 ########
527 # alias with file implicit :full and file has :long aliasses
528 use charnames ":alias" => ":xyzzy";
529 "Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
530 FILE
531 #!perl
532 (   e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
533     a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
534     );
535 EXPECT
536 $