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