VMS %ENV fix (follow-up to 18852)
[p5sagit/p5-mst-13.2.git] / ext / Unicode / Normalize / t / func.t
CommitLineData
ac5ea531 1
4a2e806c 2BEGIN {
3 if (ord("A") == 193) {
f027f502 4 print "1..0 # Unicode::Normalize not ported to EBCDIC\n";
5 exit 0;
4a2e806c 6 }
7}
8
6c941e0c 9BEGIN {
10 if ($ENV{PERL_CORE}) {
11 chdir('t') if -d 't';
12 @INC = qw(../lib);
13 }
14}
15
ac5ea531 16#########################
17
18use Test;
19use strict;
20use warnings;
f027f502 21BEGIN { plan tests => 13 };
ac5ea531 22use Unicode::Normalize qw(:all);
23ok(1); # If we made it this far, we're ok.
24
6c941e0c 25our $IsEBCDIC = ord("A") != 0x41;
26
27sub _pack_U {
28 return $IsEBCDIC
29 ? pack('U*', map utf8::unicode_to_native($_), @_)
30 : pack('U*', @_);
31}
32
33sub _unpack_U {
34 return $IsEBCDIC
35 ? map(utf8::native_to_unicode($_), unpack 'U*', shift)
36 : unpack('U*', shift);
37}
38
ac5ea531 39#########################
40
41print getCombinClass( 0) == 0
42 && getCombinClass( 768) == 230
43 && getCombinClass(1809) == 36
f027f502 44 && ($] < 5.007003 || getCombinClass(0x1D167) == 1) # Unicode 3.1
ac5ea531 45 ? "ok" : "not ok", " 2\n";
46
47print ! defined getCanon( 0)
48 && ! defined getCanon(41)
6c941e0c 49 && getCanon(0x00C0) eq _pack_U(0x0041, 0x0300)
50 && getCanon(0x00EF) eq _pack_U(0x0069, 0x0308)
51 && getCanon(0x304C) eq _pack_U(0x304B, 0x3099)
52 && getCanon(0x1EA4) eq _pack_U(0x0041, 0x0302, 0x0301)
2a204b45 53 && getCanon(0x1F82) eq "\x{03B1}\x{0313}\x{0300}\x{0345}"
6c941e0c 54 && getCanon(0x1FAF) eq _pack_U(0x03A9, 0x0314, 0x0342, 0x0345)
55 && getCanon(0xAC00) eq _pack_U(0x1100, 0x1161)
56 && getCanon(0xAE00) eq _pack_U(0x1100, 0x1173, 0x11AF)
ac5ea531 57 && ! defined getCanon(0x212C)
58 && ! defined getCanon(0x3243)
6c941e0c 59 && getCanon(0xFA2D) eq _pack_U(0x9DB4)
ac5ea531 60 ? "ok" : "not ok", " 3\n";
61
62print ! defined getCompat( 0)
63 && ! defined getCompat(41)
6c941e0c 64 && getCompat(0x00C0) eq _pack_U(0x0041, 0x0300)
65 && getCompat(0x00EF) eq _pack_U(0x0069, 0x0308)
66 && getCompat(0x304C) eq _pack_U(0x304B, 0x3099)
67 && getCompat(0x1EA4) eq _pack_U(0x0041, 0x0302, 0x0301)
68 && getCompat(0x1F82) eq _pack_U(0x03B1, 0x0313, 0x0300, 0x0345)
69 && getCompat(0x1FAF) eq _pack_U(0x03A9, 0x0314, 0x0342, 0x0345)
70 && getCompat(0x212C) eq _pack_U(0x0042)
71 && getCompat(0x3243) eq _pack_U(0x0028, 0x81F3, 0x0029)
72 && getCompat(0xAC00) eq _pack_U(0x1100, 0x1161)
73 && getCompat(0xAE00) eq _pack_U(0x1100, 0x1173, 0x11AF)
74 && getCompat(0xFA2D) eq _pack_U(0x9DB4)
ac5ea531 75 ? "ok" : "not ok", " 4\n";
76
2a204b45 77print ! defined getComposite( 0, 0)
78 && ! defined getComposite( 0, 41)
79 && ! defined getComposite(41, 0)
80 && ! defined getComposite(41, 41)
81 && ! defined getComposite(12, 0x0300)
82 && ! defined getComposite(0x0055, 0xFF00)
83 && 0x00C0 == getComposite(0x0041, 0x0300)
ac5ea531 84 && 0x00D9 == getComposite(0x0055, 0x0300)
85 && 0x1E14 == getComposite(0x0112, 0x0300)
86 && 0xAC00 == getComposite(0x1100, 0x1161)
87 && 0xADF8 == getComposite(0x1100, 0x1173)
ab8fe378 88 && ! defined getComposite(0x1100, 0x11AF)
89 && ! defined getComposite(0x1173, 0x11AF)
8f118dcd 90 && ! defined getComposite(0xAC00, 0x11A7)
91 && 0xAC01 == getComposite(0xAC00, 0x11A8)
ac5ea531 92 && 0xAE00 == getComposite(0xADF8, 0x11AF)
93 ? "ok" : "not ok", " 5\n";
94
2a204b45 95print ! isExclusion( 0)
96 && ! isExclusion(41)
8f118dcd 97 && isExclusion(2392) # DEVANAGARI LETTER QA
98 && isExclusion(3907) # TIBETAN LETTER GHA
99 && isExclusion(64334) # HEBREW LETTER PE WITH RAFE
ac5ea531 100 ? "ok" : "not ok", " 6\n";
2a204b45 101
8f118dcd 102print ! isSingleton( 0)
103 && isSingleton(0x212B) # ANGSTROM SIGN
104 ? "ok" : "not ok", " 7\n";
105
106print reorder("") eq ""
6c941e0c 107 && reorder(_pack_U(0x0041, 0x0300, 0x0315, 0x0313, 0x031b, 0x0061))
108 eq _pack_U(0x0041, 0x031b, 0x0300, 0x0313, 0x0315, 0x0061)
109 && reorder(_pack_U(0x00C1, 0x0300, 0x0315, 0x0313, 0x031b,
8f118dcd 110 0x0061, 0x309A, 0x3099))
6c941e0c 111 eq _pack_U(0x00C1, 0x031b, 0x0300, 0x0313, 0x0315,
8f118dcd 112 0x0061, 0x309A, 0x3099)
113 ? "ok" : "not ok", " 8\n";
114
115sub answer { defined $_[0] ? $_[0] ? "YES" : "NO" : "MAYBE" }
116
117print answer(checkNFD("")) eq "YES"
118 && answer(checkNFC("")) eq "YES"
119 && answer(checkNFKD("")) eq "YES"
120 && answer(checkNFKC("")) eq "YES"
121 && answer(check("NFD", "")) eq "YES"
122 && answer(check("NFC", "")) eq "YES"
123 && answer(check("NFKD","")) eq "YES"
124 && answer(check("NFKC","")) eq "YES"
125# U+0000 to U+007F are prenormalized in all the normalization forms.
126 && answer(checkNFD("AZaz\t12!#`")) eq "YES"
127 && answer(checkNFC("AZaz\t12!#`")) eq "YES"
128 && answer(checkNFKD("AZaz\t12!#`")) eq "YES"
129 && answer(checkNFKC("AZaz\t12!#`")) eq "YES"
130 && answer(check("D", "AZaz\t12!#`")) eq "YES"
131 && answer(check("C", "AZaz\t12!#`")) eq "YES"
132 && answer(check("KD","AZaz\t12!#`")) eq "YES"
133 && answer(check("KC","AZaz\t12!#`")) eq "YES"
134 ? "ok" : "not ok", " 9\n";
135
136print 1
6c941e0c 137 && answer(checkNFD(NFD(_pack_U(0xC1, 0x1100, 0x1173, 0x11AF)))) eq "YES"
138 && answer(checkNFD(_pack_U(0x20, 0xC1, 0x1100, 0x1173, 0x11AF))) eq "NO"
139 && answer(checkNFC(_pack_U(0x20, 0xC1, 0x1173, 0x11AF))) eq "MAYBE"
140 && answer(checkNFC(_pack_U(0x20, 0xC1, 0xAE00, 0x1100))) eq "YES"
141 && answer(checkNFC(_pack_U(0x20, 0xC1, 0xAE00, 0x1100, 0x300))) eq "MAYBE"
142 && answer(checkNFC(_pack_U(0x20, 0xC1, 0xFF71, 0x2025))) eq "YES"
143 && answer(check("NFC", _pack_U(0x20, 0xC1, 0x212B, 0x300))) eq "NO"
144 && answer(checkNFKD(_pack_U(0x20, 0xC1, 0xFF71, 0x2025))) eq "NO"
145 && answer(checkNFKC(_pack_U(0x20, 0xC1, 0xAE00, 0x2025))) eq "NO"
8f118dcd 146 ? "ok" : "not ok", " 10\n";
f027f502 147
148"012ABC" =~ /(\d+)(\w+)/;
149print "012" eq NFC $1 && "ABC" eq NFC $2
150 ? "ok" : "not ok", " 11\n";
151
152print "012" eq normalize('C', $1) && "ABC" eq normalize('C', $2)
153 ? "ok" : "not ok", " 12\n";
154
155print "012" eq normalize('NFC', $1) && "ABC" eq normalize('NFC', $2)
156 ? "ok" : "not ok", " 13\n";
157 # s/^NF// in normalize() must not prevent using $1, $&, etc.
158