This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Major utf8 test reorganisation and rewrite.
[perl5.git] / t / lib / charnames.t
CommitLineData
423cee85
JH
1#!./perl
2
3BEGIN {
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
423cee85
JH
7 }
8}
9
10$| = 1;
4765795a 11print "1..16\n";
423cee85
JH
12
13use charnames ':full';
14
f70c35af 15print "not " unless "Here\N{EXCLAMATION MARK}?" eq "Here\041?";
423cee85
JH
16print "ok 1\n";
17
c82a54e6 18{
5d9a6404 19 use bytes; # TEST -utf8 can switch utf8 on
c82a54e6
IZ
20
21 print "# \$res=$res \$\@='$@'\nnot "
22 if $res = eval <<'EOE'
423cee85 23use charnames ":full";
4a2d328f 24"Here: \N{CYRILLIC SMALL LETTER BE}!";
423cee85
JH
251
26EOE
c82a54e6
IZ
27 or $@ !~ /above 0xFF/;
28 print "ok 2\n";
29 # print "# \$res=$res \$\@='$@'\n";
423cee85 30
c82a54e6
IZ
31 print "# \$res=$res \$\@='$@'\nnot "
32 if $res = eval <<'EOE'
423cee85 33use charnames 'cyrillic';
4a2d328f 34"Here: \N{Be}!";
423cee85
JH
351
36EOE
c82a54e6
IZ
37 or $@ !~ /CYRILLIC CAPITAL LETTER BE.*above 0xFF/;
38 print "ok 3\n";
39}
423cee85
JH
40
41# If octal representation of unicode char is \0xyzt, then the utf8 is \3xy\2zt
42$encoded_be = "\320\261";
43$encoded_alpha = "\316\261";
44$encoded_bet = "\327\221";
b896c7a5 45$encoded_deseng = "\360\220\221\215";
c5cc3500
GS
46
47sub to_bytes {
f9a63242 48 pack"a*", shift;
c5cc3500
GS
49}
50
423cee85
JH
51{
52 use charnames ':full';
423cee85 53
c5cc3500 54 print "not " unless to_bytes("\N{CYRILLIC SMALL LETTER BE}") eq $encoded_be;
423cee85
JH
55 print "ok 4\n";
56
57 use charnames qw(cyrillic greek :short);
58
c5cc3500 59 print "not " unless to_bytes("\N{be},\N{alpha},\N{hebrew:bet}")
423cee85
JH
60 eq "$encoded_be,$encoded_alpha,$encoded_bet";
61 print "ok 5\n";
62}
e1992b6d
GS
63
64{
65 use charnames ':full';
66 print "not " unless "\x{263a}" eq "\N{WHITE SMILING FACE}";
67 print "ok 6\n";
68 print "not " unless length("\x{263a}") == 1;
69 print "ok 7\n";
70 print "not " unless length("\N{WHITE SMILING FACE}") == 1;
71 print "ok 8\n";
72 print "not " unless sprintf("%vx", "\x{263a}") eq "263a";
73 print "ok 9\n";
74 print "not " unless sprintf("%vx", "\N{WHITE SMILING FACE}") eq "263a";
75 print "ok 10\n";
f08d6ad9
GS
76 print "not " unless sprintf("%vx", "\xFF\N{WHITE SMILING FACE}") eq "ff.263a";
77 print "ok 11\n";
78 print "not " unless sprintf("%vx", "\x{ff}\N{WHITE SMILING FACE}") eq "ff.263a";
79 print "ok 12\n";
e1992b6d 80}
c00525d4
SP
81
82{
83 use charnames qw(:full);
55eda711 84 use utf8;
c00525d4
SP
85
86 my $x = "\x{221b}";
87 my $named = "\N{CUBE ROOT}";
88
89 print "not " unless ord($x) == ord($named);
90 print "ok 13\n";
91}
92
f9a63242
JH
93{
94 use charnames qw(:full);
55eda711 95 use utf8;
f9a63242
JH
96 print "not " unless "\x{100}\N{CENT SIGN}" eq "\x{100}"."\N{CENT SIGN}";
97 print "ok 14\n";
98}
99
b896c7a5
A
100{
101 use charnames ':full';
102
103 print "not "
104 unless to_bytes("\N{DESERET SMALL LETTER ENG}") eq $encoded_deseng;
105 print "ok 15\n";
4765795a 106}
b896c7a5 107
4765795a
JH
108{
109 # 20001114.001
110
111 if (ord("Ä") == 0xc4) { # Try to do this only on Latin-1.
112 use charnames ':full';
113 my $text = "\N{LATIN CAPITAL LETTER A WITH DIAERESIS}";
114 print "not " unless $text eq "\xc4" && ord($text) == 0xc4;
115 print "ok 16\n";
116 } else {
117 print "ok 16 # Skip: not Latin-1\n";
118 }
b896c7a5
A
119}
120