Integrate mainline (Win2k/MinGW all ok except threads/t/end.t)
[p5sagit/p5-mst-13.2.git] / ext / Unicode / Normalize / t / func.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 BEGIN {
5     if (ord("A") == 193) {
6        print "1..0 # Unicode::Normalize not ported to EBCDIC\n";
7        exit 0;
8     }
9 }
10
11 #########################
12
13 use Test;
14 use strict;
15 use warnings;
16 BEGIN { plan tests => 10 };
17 use Unicode::Normalize qw(:all);
18 ok(1); # If we made it this far, we're ok.
19
20 #########################
21
22 print getCombinClass(   0) == 0
23    && getCombinClass( 768) == 230
24    && getCombinClass(1809) == 36
25 #  && getCombinClass(119143) == 1 # U+1D167, a Unicode 3.1 character
26   ? "ok" : "not ok", " 2\n";
27
28 print ! defined getCanon( 0)
29    && ! defined getCanon(41)
30    && getCanon(0x00C0) eq pack('U*', 0x0041, 0x0300)
31    && getCanon(0x00EF) eq pack('U*', 0x0069, 0x0308)
32    && getCanon(0x304C) eq pack('U*', 0x304B, 0x3099)
33    && getCanon(0x1EA4) eq pack('U*', 0x0041, 0x0302, 0x0301)
34    && getCanon(0x1F82) eq "\x{03B1}\x{0313}\x{0300}\x{0345}"
35    && getCanon(0x1FAF) eq pack('U*', 0x03A9, 0x0314, 0x0342, 0x0345)
36    && getCanon(0xAC00) eq pack('U*', 0x1100, 0x1161)
37    && getCanon(0xAE00) eq pack('U*', 0x1100, 0x1173, 0x11AF)
38    && ! defined getCanon(0x212C)
39    && ! defined getCanon(0x3243)
40    && getCanon(0xFA2D) eq pack('U*', 0x9DB4)
41   ? "ok" : "not ok", " 3\n";
42
43 print ! defined getCompat( 0)
44    && ! defined getCompat(41)
45    && getCompat(0x00C0) eq pack('U*', 0x0041, 0x0300)
46    && getCompat(0x00EF) eq pack('U*', 0x0069, 0x0308)
47    && getCompat(0x304C) eq pack('U*', 0x304B, 0x3099)
48    && getCompat(0x1EA4) eq pack('U*', 0x0041, 0x0302, 0x0301)
49    && getCompat(0x1F82) eq pack('U*', 0x03B1, 0x0313, 0x0300, 0x0345)
50    && getCompat(0x1FAF) eq pack('U*', 0x03A9, 0x0314, 0x0342, 0x0345)
51    && getCompat(0x212C) eq pack('U*', 0x0042)
52    && getCompat(0x3243) eq pack('U*', 0x0028, 0x81F3, 0x0029)
53    && getCompat(0xAC00) eq pack('U*', 0x1100, 0x1161)
54    && getCompat(0xAE00) eq pack('U*', 0x1100, 0x1173, 0x11AF)
55    && getCompat(0xFA2D) eq pack('U*', 0x9DB4)
56   ? "ok" : "not ok", " 4\n";
57
58 print ! defined getComposite( 0,  0)
59    && ! defined getComposite( 0, 41)
60    && ! defined getComposite(41,  0)
61    && ! defined getComposite(41, 41)
62    && ! defined getComposite(12, 0x0300)
63    && ! defined getComposite(0x0055, 0xFF00)
64    && 0x00C0 == getComposite(0x0041, 0x0300)
65    && 0x00D9 == getComposite(0x0055, 0x0300)
66    && 0x1E14 == getComposite(0x0112, 0x0300)
67    && 0xAC00 == getComposite(0x1100, 0x1161)
68    && 0xADF8 == getComposite(0x1100, 0x1173)
69    && ! defined getComposite(0x1100, 0x11AF)
70    && ! defined getComposite(0x1173, 0x11AF)
71    && ! defined getComposite(0xAC00, 0x11A7)
72    && 0xAC01 == getComposite(0xAC00, 0x11A8)
73    && 0xAE00 == getComposite(0xADF8, 0x11AF)
74   ? "ok" : "not ok", " 5\n";
75
76 print ! isExclusion( 0)
77    && ! isExclusion(41)
78    && isExclusion(2392)  # DEVANAGARI LETTER QA
79    && isExclusion(3907)  # TIBETAN LETTER GHA
80    && isExclusion(64334) # HEBREW LETTER PE WITH RAFE
81   ? "ok" : "not ok", " 6\n";
82
83 print ! isSingleton( 0)
84    && isSingleton(0x212B) # ANGSTROM SIGN
85   ? "ok" : "not ok", " 7\n";
86
87 print reorder("") eq ""
88    && reorder(pack("U*", 0x0041, 0x0300, 0x0315, 0x0313, 0x031b, 0x0061))
89       eq pack("U*", 0x0041, 0x031b, 0x0300, 0x0313, 0x0315, 0x0061)
90    && reorder(pack("U*", 0x00C1, 0x0300, 0x0315, 0x0313, 0x031b,
91         0x0061, 0x309A, 0x3099))
92       eq pack("U*", 0x00C1, 0x031b, 0x0300, 0x0313, 0x0315,
93         0x0061, 0x309A, 0x3099)
94   ? "ok" : "not ok", " 8\n";
95
96 sub answer { defined $_[0] ? $_[0] ? "YES" : "NO" : "MAYBE" }
97
98 print answer(checkNFD(""))  eq "YES"
99   &&  answer(checkNFC(""))  eq "YES"
100   &&  answer(checkNFKD("")) eq "YES"
101   &&  answer(checkNFKC("")) eq "YES"
102   &&  answer(check("NFD", "")) eq "YES"
103   &&  answer(check("NFC", "")) eq "YES"
104   &&  answer(check("NFKD","")) eq "YES"
105   &&  answer(check("NFKC","")) eq "YES"
106 # U+0000 to U+007F are prenormalized in all the normalization forms.
107   && answer(checkNFD("AZaz\t12!#`"))  eq "YES"
108   && answer(checkNFC("AZaz\t12!#`"))  eq "YES"
109   && answer(checkNFKD("AZaz\t12!#`")) eq "YES"
110   && answer(checkNFKC("AZaz\t12!#`")) eq "YES"
111   && answer(check("D", "AZaz\t12!#`")) eq "YES"
112   && answer(check("C", "AZaz\t12!#`")) eq "YES"
113   && answer(check("KD","AZaz\t12!#`")) eq "YES"
114   && answer(check("KC","AZaz\t12!#`")) eq "YES"
115   ? "ok" : "not ok", " 9\n";
116
117 print 1
118   && answer(checkNFD(NFD(pack('U*', 0xC1, 0x1100, 0x1173, 0x11AF)))) eq "YES"
119   && answer(checkNFD(pack('U*', 0x20, 0xC1, 0x1100, 0x1173, 0x11AF))) eq "NO"
120   && answer(checkNFC(pack('U*', 0x20, 0xC1, 0x1173, 0x11AF))) eq "MAYBE"
121   && answer(checkNFC(pack('U*', 0x20, 0xC1, 0xAE00, 0x1100))) eq "YES"
122   && answer(checkNFC(pack('U*', 0x20, 0xC1, 0xAE00, 0x1100, 0x300))) eq "MAYBE"
123   && answer(checkNFC(pack('U*', 0x20, 0xC1, 0xFF71, 0x2025))) eq "YES"
124   && answer(check("NFC", pack('U*', 0x20, 0xC1, 0x212B, 0x300))) eq "NO"
125   && answer(checkNFKD(pack('U*', 0x20, 0xC1, 0xFF71, 0x2025))) eq "NO"
126   && answer(checkNFKC(pack('U*', 0x20, 0xC1, 0xAE00, 0x2025))) eq "NO"
127   ? "ok" : "not ok", " 10\n";