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