Cygwin doesn't like initing the $0 mutex in perl_construct()
[p5sagit/p5-mst-13.2.git] / lib / charnames.t
CommitLineData
423cee85 1#!./perl
2
52ea3e69 3my @WARN;
4
423cee85 5BEGIN {
6 unless(grep /blib/, @INC) {
7 chdir 't' if -d 't';
20822f61 8 @INC = '../lib';
143a3e5e 9 require './test.pl';
423cee85 10 }
52ea3e69 11 $SIG{__WARN__} = sub { push @WARN, @_ };
423cee85 12}
13
14$| = 1;
822ebcc8 15
51cf30b6 16print "1..73\n";
423cee85 17
18use charnames ':full';
19
93979888 20print "not " unless "Here\N{EXCLAMATION MARK}?" eq "Here!?";
423cee85 21print "ok 1\n";
22
c82a54e6 23{
5d9a6404 24 use bytes; # TEST -utf8 can switch utf8 on
c82a54e6 25
26 print "# \$res=$res \$\@='$@'\nnot "
27 if $res = eval <<'EOE'
423cee85 28use charnames ":full";
4a2d328f 29"Here: \N{CYRILLIC SMALL LETTER BE}!";
423cee85 301
31EOE
c82a54e6 32 or $@ !~ /above 0xFF/;
33 print "ok 2\n";
34 # print "# \$res=$res \$\@='$@'\n";
423cee85 35
c82a54e6 36 print "# \$res=$res \$\@='$@'\nnot "
37 if $res = eval <<'EOE'
423cee85 38use charnames 'cyrillic';
4a2d328f 39"Here: \N{Be}!";
423cee85 401
41EOE
c82a54e6 42 or $@ !~ /CYRILLIC CAPITAL LETTER BE.*above 0xFF/;
43 print "ok 3\n";
44}
423cee85 45
46# If octal representation of unicode char is \0xyzt, then the utf8 is \3xy\2zt
210db7fc 47if (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}
53else { # 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}
c5cc3500 60
61sub to_bytes {
f9a63242 62 pack"a*", shift;
c5cc3500 63}
64
423cee85 65{
66 use charnames ':full';
423cee85 67
c5cc3500 68 print "not " unless to_bytes("\N{CYRILLIC SMALL LETTER BE}") eq $encoded_be;
423cee85 69 print "ok 4\n";
70
71 use charnames qw(cyrillic greek :short);
72
c5cc3500 73 print "not " unless to_bytes("\N{be},\N{alpha},\N{hebrew:bet}")
423cee85 74 eq "$encoded_be,$encoded_alpha,$encoded_bet";
75 print "ok 5\n";
76}
e1992b6d 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";
f08d6ad9 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";
e1992b6d 94}
c00525d4 95
96{
97 use charnames qw(:full);
55eda711 98 use utf8;
51cf30b6 99
c00525d4 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
f9a63242 107{
108 use charnames qw(:full);
55eda711 109 use utf8;
f9a63242 110 print "not " unless "\x{100}\N{CENT SIGN}" eq "\x{100}"."\N{CENT SIGN}";
111 print "ok 14\n";
112}
113
b896c7a5 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";
4765795a 120}
b896c7a5 121
4765795a 122{
51cf30b6 123 # 20001114.001
4765795a 124
4c53e876 125 no utf8; # naked Latin-1
3ba0e062 126
4765795a 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 }
b896c7a5 135}
136
daf0d493 137{
138 print "not " unless charnames::viacode(0x1234) eq "ETHIOPIC SYLLABLE SEE";
139 print "ok 17\n";
140
a23c04e4 141 # Unused Hebrew.
11881cb4 142 print "not " if defined charnames::viacode(0x0590);
daf0d493 143 print "ok 18\n";
144}
145
146{
147 print "not " unless
51b0dbc4 148 sprintf("%04X", charnames::vianame("GOTHIC LETTER AHSA")) eq "10330";
daf0d493 149 print "ok 19\n";
150
151 print "not " if
152 defined charnames::vianame("NONE SUCH");
153 print "ok 20\n";
154}
4e2cda5d 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
51b0dbc4 163 sprintf("%04X", charnames::vianame("GOTHIC LETTER AHSA")) eq "10330";
4e2cda5d 164 print "ok 22\n";
165
166}
301a3cda 167
822ebcc8 168print "not " unless "\N{CHARACTER TABULATION}" eq "\t";
301a3cda 169print "ok 23\n";
170
171print "not " unless "\N{ESCAPE}" eq "\e";
172print "ok 24\n";
173
174print "not " unless "\N{NULL}" eq "\c@";
175print "ok 25\n";
176
eb380778 177if ($^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}
188else
189{
190 print "not " unless "\N{LINE FEED (LF)}" eq "\n";
191 print "ok 26\n";
52ea3e69 192
eb380778 193 print "not " unless "\N{LINE FEED}" eq "\n";
194 print "ok 27\n";
52ea3e69 195
eb380778 196 print "not " unless "\N{LF}" eq "\n";
197 print "ok 28\n";
198}
52ea3e69 199
a2e77dd4 200my $nel = ord("A") == 193 ? qr/^(?:\x15|\x25)$/ : qr/^\x85$/;
201
202print "not " unless "\N{NEXT LINE (NEL)}" =~ $nel;
52ea3e69 203print "ok 29\n";
204
a2e77dd4 205print "not " unless "\N{NEXT LINE}" =~ $nel;
52ea3e69 206print "ok 30\n";
207
a2e77dd4 208print "not " unless "\N{NEL}" =~ $nel;
51e9e896 209print "ok 31\n";
210
274085e3 211print "not " unless "\N{BYTE ORDER MARK}" eq chr(0xFEFF);
51e9e896 212print "ok 32\n";
213
d7d589a8 214print "not " unless "\N{BOM}" eq chr(0xFEFF);
51e9e896 215print "ok 33\n";
216
52ea3e69 217{
218 use warnings 'deprecated';
219
220 print "not " unless "\N{HORIZONTAL TABULATION}" eq "\t";
51e9e896 221 print "ok 34\n";
52ea3e69 222
223 print "not " unless grep { /"HORIZONTAL TABULATION" is deprecated/ } @WARN;
51e9e896 224 print "ok 35\n";
822ebcc8 225
52ea3e69 226 no warnings 'deprecated';
227
228 print "not " unless "\N{VERTICAL TABULATION}" eq "\013";
51e9e896 229 print "ok 36\n";
52ea3e69 230
231 print "not " if grep { /"VERTICAL TABULATION" is deprecated/ } @WARN;
51e9e896 232 print "ok 37\n";
52ea3e69 233}
822ebcc8 234
274085e3 235print "not " unless charnames::viacode(0xFEFF) eq "ZERO WIDTH NO-BREAK SPACE";
a23c04e4 236print "ok 38\n";
237
872c91ae 238{
239 use warnings;
240 print "not " unless ord("\N{BOM}") == 0xFEFF;
241 print "ok 39\n";
242}
243
24b5d5cc 244print "not " unless ord("\N{ZWNJ}") == 0x200C;
245print "ok 40\n";
246
247print "not " unless ord("\N{ZWJ}") == 0x200D;
248print "ok 41\n";
dbc0d4f2 249
250print "not " unless "\N{U+263A}" eq "\N{WHITE SMILING FACE}";
251print "ok 42\n";
252
51b0dbc4 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
00d835f2 263print "not " if defined charnames::viacode(0x110000);
51b0dbc4 264print "ok 45\n";
00d835f2 265
266print "not " if grep { /you asked for U+110000/ } @WARN;
51b0dbc4 267print "ok 46\n";
35c0985d 268
269
270# ---- Alias extensions
271
272my $tmpfile = "tmp0000";
273my $alifile = "../lib/unicore/xyzzy_alias.pl";
274my $i = 0;
2751 while -e ++$tmpfile;
276END { if ($tmpfile) { 1 while unlink $tmpfile; } }
277
278my @prgs;
279{ local $/ = undef;
280 @prgs = split "\n########\n", <DATA>;
281 }
282
283my $i = 46;
284for (@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 }
143a3e5e 296 my $res = runperl( switches => $switch,
297 progfile => $tmpfile,
298 stderr => 1 );
35c0985d 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__
51cf30b6 330# unsupported pragma
331use charnames ":scoobydoo";
332"Here: \N{e_ACUTE}!\n";
333EXPECT
334unsupported special ':scoobydoo' in charnames at
335########
35c0985d 336# wrong type of alias (missing colon)
337use charnames "alias";
338"Here: \N{e_ACUTE}!\n";
339EXPECT
51cf30b6 340Unknown charname 'e_ACUTE' at
35c0985d 341########
342# alias without an argument
343use charnames ":alias";
344"Here: \N{e_ACUTE}!\n";
345EXPECT
51cf30b6 346:alias needs an argument in charnames at
347########
348# reversed sequence
349use charnames ":alias" => ":full";
350"Here: \N{e_ACUTE}!\n";
351EXPECT
352:alias cannot use existing pragma :full \(reversed order\?\) at
35c0985d 353########
354# alias with hashref but no :full
355use charnames ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
356"Here: \N{e_ACUTE}!\n";
357EXPECT
358Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
359########
360# alias with hashref but with :short
361use charnames ":short", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
362"Here: \N{e_ACUTE}!\n";
363EXPECT
364Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
365########
366# alias with hashref to :full OK
367use charnames ":full", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
368"Here: \N{e_ACUTE}!\n";
369EXPECT
370$
371########
372# alias with hashref to :short but using :full
373use charnames ":full", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE" };
374"Here: \N{e_ACUTE}!\n";
375EXPECT
376Unknown charname 'LATIN:e WITH ACUTE' at
377########
378# alias with hashref to :short OK
379use charnames ":short", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE" };
380"Here: \N{e_ACUTE}!\n";
381EXPECT
382$
383########
384# alias with bad hashref
385use charnames ":short", ":alias" => "e_ACUTE";
386"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
387EXPECT
51cf30b6 388unicore/e_ACUTE_alias.pl cannot be used as alias file for charnames at
35c0985d 389########
390# alias with arrayref
391use charnames ":short", ":alias" => [ e_ACUTE => "LATIN:e WITH ACUTE" ];
392"Here: \N{e_ACUTE}!\n";
393EXPECT
394Only HASH reference supported as argument to :alias at
395########
396# alias with bad hashref
397use charnames ":short", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE", "a_ACUTE" };
398"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
399EXPECT
400Use of uninitialized value in string eq at
401########
402# alias with hashref two aliases
403use charnames ":short", ":alias" => {
404 e_ACUTE => "LATIN:e WITH ACUTE",
405 a_ACUTE => "",
406 };
407"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
408EXPECT
409Unknown charname '' at
410########
411# alias with hashref two aliases
412use 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";
417EXPECT
418$
419########
420# alias with hashref using mixed aliasses
421use 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";
426EXPECT
427Unknown charname 'LATIN SMALL LETTER A WITH ACUT' at
428########
429# alias with hashref using mixed aliasses
430use 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";
435EXPECT
436Unknown charname 'LATIN SMALL LETTER A WITH ACUTE' at
437########
438# alias with hashref using mixed aliasses
439use 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";
444EXPECT
445Unknown charname 'LATIN:e WITH ACUTE' at
446########
447# alias with nonexisting file
448use charnames ":full", ":alias" => "xyzzy";
449"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
450EXPECT
51cf30b6 451unicore/xyzzy_alias.pl cannot be used as alias file for charnames at
452########
453# alias with bad file name
454use charnames ":full", ":alias" => "xy 7-";
455"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
456EXPECT
457Charnames alias files can only have identifier characters at
458########
459# alias with non_absolute (existing) file name (which it should /not/ use)
460use charnames ":full", ":alias" => "perl";
461"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
462EXPECT
463unicore/perl_alias.pl cannot be used as alias file for charnames at
35c0985d 464########
465# alias with bad file
466use charnames ":full", ":alias" => "xyzzy";
467"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
468FILE
469#!perl
4700;
471EXPECT
51cf30b6 472unicore/xyzzy_alias.pl did not return a \(valid\) list of alias pairs at
35c0985d 473########
474# alias with file with empty list
475use charnames ":full", ":alias" => "xyzzy";
476"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
477FILE
478#!perl
479();
480EXPECT
481Unknown charname 'e_ACUTE' at
482########
483# alias with file OK but file has :short aliasses
484use charnames ":full", ":alias" => "xyzzy";
485"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
486FILE
487#!perl
488( e_ACUTE => "LATIN:e WITH ACUTE",
489 a_ACUTE => "LATIN:a WITH ACUTE",
490 );
491EXPECT
492Unknown charname 'LATIN:e WITH ACUTE' at
493########
494# alias with :short and file OK
495use charnames ":short", ":alias" => "xyzzy";
496"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
497FILE
498#!perl
499( e_ACUTE => "LATIN:e WITH ACUTE",
500 a_ACUTE => "LATIN:a WITH ACUTE",
501 );
502EXPECT
503$
504########
505# alias with :short and file OK has :long aliasses
506use charnames ":short", ":alias" => "xyzzy";
507"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
508FILE
509#!perl
510( e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
511 a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
512 );
513EXPECT
514Unknown charname 'LATIN SMALL LETTER E WITH ACUTE' at
515########
516# alias with file implicit :full but file has :short aliasses
517use charnames ":alias" => ":xyzzy";
518"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
519FILE
520#!perl
521( e_ACUTE => "LATIN:e WITH ACUTE",
522 a_ACUTE => "LATIN:a WITH ACUTE",
523 );
524EXPECT
525Unknown charname 'LATIN:e WITH ACUTE' at
526########
527# alias with file implicit :full and file has :long aliasses
528use charnames ":alias" => ":xyzzy";
529"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
530FILE
531#!perl
532( e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
533 a_ACUTE => "LATIN SMALL LETTER A WITH ACUTE",
534 );
535EXPECT
536$