Upgrade to Unicode::Normalize 1.02
[p5sagit/p5-mst-13.2.git] / ext / Unicode / Normalize / t / fcdc.t
CommitLineData
82e740b6 1
2BEGIN {
3 unless ("A" eq pack('U', 0x41)) {
4 print "1..0 # Unicode::Normalize " .
5 "cannot stringify a Unicode code point\n";
6 exit 0;
7 }
8}
9
10BEGIN {
11 if ($ENV{PERL_CORE}) {
12 chdir('t') if -d 't';
13 @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
14 }
15}
16
17#########################
18
19use Test;
20use strict;
21use warnings;
2b8d773d 22BEGIN { plan tests => 70 };
82e740b6 23use Unicode::Normalize qw(:all);
24ok(1); # If we made it this far, we're ok.
25
fe067ad9 26sub _pack_U { Unicode::Normalize::pack_U(@_) }
27sub hexU { _pack_U map hex, split ' ', shift }
82e740b6 28sub answer { defined $_[0] ? $_[0] ? "YES" : "NO" : "MAYBE" }
29
30#########################
31
fe067ad9 32ok(FCD(''), "");
33ok(FCC(''), "");
34ok(FCD('A'), "A");
35ok(FCC('A'), "A");
36
37ok(normalize('FCD', ""), "");
38ok(normalize('FCC', ""), "");
39ok(normalize('FCC', "A"), "A");
40ok(normalize('FCD', "A"), "A");
41
42# if checkFCD is YES, the return value from FCD should be same as the original
43ok(FCD(hexU("00C5")), hexU("00C5")); # A with ring above
44ok(FCD(hexU("0041 030A")), hexU("0041 030A")); # A+ring
45ok(FCD(hexU("0041 0327 030A")), hexU("0041 0327 030A")); # A+cedilla+ring
46ok(FCD(hexU("AC01 1100 1161")), hexU("AC01 1100 1161")); # hangul
47ok(FCD(hexU("212B F900")), hexU("212B F900")); # compat
48
49ok(normalize('FCD', hexU("00C5")), hexU("00C5"));
50ok(normalize('FCD', hexU("0041 030A")), hexU("0041 030A"));
51ok(normalize('FCD', hexU("0041 0327 030A")), hexU("0041 0327 030A"));
52ok(normalize('FCD', hexU("AC01 1100 1161")), hexU("AC01 1100 1161"));
53ok(normalize('FCD', hexU("212B F900")), hexU("212B F900"));
54
55# if checkFCD is MAYBE or NO, FCD returns NFD (this behavior isn't documented)
56ok(FCD(hexU("00C5 0327")), hexU("0041 0327 030A"));
57ok(FCD(hexU("0041 030A 0327")), hexU("0041 0327 030A"));
58ok(FCD(hexU("00C5 0327")), NFD(hexU("00C5 0327")));
59ok(FCD(hexU("0041 030A 0327")), NFD(hexU("0041 030A 0327")));
60
61ok(normalize('FCD', hexU("00C5 0327")), hexU("0041 0327 030A"));
62ok(normalize('FCD', hexU("0041 030A 0327")), hexU("0041 0327 030A"));
63ok(normalize('FCD', hexU("00C5 0327")), NFD(hexU("00C5 0327")));
64ok(normalize('FCD', hexU("0041 030A 0327")), NFD(hexU("0041 030A 0327")));
65
82e740b6 66ok(answer(checkFCD('')), 'YES');
67ok(answer(checkFCD('A')), 'YES');
68ok(answer(checkFCD("\x{030A}")), 'YES'); # 030A;COMBINING RING ABOVE
fe067ad9 69ok(answer(checkFCD("\x{0327}")), 'YES'); # 0327;COMBINING CEDILLA
82e740b6 70ok(answer(checkFCD(_pack_U(0x00C5))), 'YES'); # A with ring above
fe067ad9 71ok(answer(checkFCD(hexU("0041 030A"))), 'YES'); # A+ring
72ok(answer(checkFCD(hexU("0041 0327 030A"))), 'YES'); # A+cedilla+ring
73ok(answer(checkFCD(hexU("0041 030A 0327"))), 'NO'); # A+ring+cedilla
74ok(answer(checkFCD(hexU("00C5 0327"))), 'NO'); # A-ring+cedilla
75ok(answer(checkNFC(hexU("00C5 0327"))), 'MAYBE'); # NFC: A-ring+cedilla
76ok(answer(check("FCD", hexU("00C5 0327"))), 'NO');
77ok(answer(check("NFC", hexU("00C5 0327"))), 'MAYBE');
82e740b6 78ok(answer(checkFCD("\x{AC01}\x{1100}\x{1161}")), 'YES'); # hangul
79ok(answer(checkFCD("\x{212B}\x{F900}")), 'YES'); # compat
80
fe067ad9 81ok(answer(checkFCD(hexU("1EA7 05AE 0315 0062"))), "NO");
82ok(answer(checkFCC(hexU("1EA7 05AE 0315 0062"))), "NO");
83ok(answer(check('FCD', hexU("1EA7 05AE 0315 0062"))), "NO");
84ok(answer(check('FCC', hexU("1EA7 05AE 0315 0062"))), "NO");
82e740b6 85
fe067ad9 86ok(FCC(hexU("00C5 0327")), hexU("0041 0327 030A"));
87ok(FCC(hexU("0045 0304 0300")), "\x{1E14}");
82e740b6 88ok(FCC("\x{1100}\x{1161}\x{1100}\x{1173}\x{11AF}"), "\x{AC00}\x{AE00}");
fe067ad9 89ok(normalize('FCC', hexU("00C5 0327")), hexU("0041 0327 030A"));
90ok(normalize('FCC', hexU("0045 0304 0300")), "\x{1E14}");
91ok(normalize('FCC', hexU("1100 1161 1100 1173 11AF")), "\x{AC00}\x{AE00}");
92
93ok(FCC("\x{0B47}\x{0300}\x{0B3E}"), "\x{0B47}\x{0300}\x{0B3E}");
94ok(FCC("\x{1100}\x{0300}\x{1161}"), "\x{1100}\x{0300}\x{1161}");
95ok(FCC("\x{0B47}\x{0B3E}\x{0300}"), "\x{0B4B}\x{0300}");
96ok(FCC("\x{1100}\x{1161}\x{0300}"), "\x{AC00}\x{0300}");
97ok(FCC("\x{0B47}\x{300}\x{0B3E}\x{327}"), "\x{0B47}\x{300}\x{0B3E}\x{327}");
98ok(FCC("\x{1100}\x{300}\x{1161}\x{327}"), "\x{1100}\x{300}\x{1161}\x{327}");
82e740b6 99
100ok(answer(checkFCC('')), 'YES');
101ok(answer(checkFCC('A')), 'YES');
102ok(answer(checkFCC("\x{030A}")), 'MAYBE'); # 030A;COMBINING RING ABOVE
103ok(answer(checkFCC("\x{0327}")), 'MAYBE'); # 0327;COMBINING CEDILLA
fe067ad9 104ok(answer(checkFCC(hexU("00C5"))), 'YES'); # A with ring above
105ok(answer(checkFCC(hexU("0041 030A"))), 'MAYBE'); # A+ring
106ok(answer(checkFCC(hexU("0041 0327 030A"))), 'MAYBE'); # A+cedilla+ring
107ok(answer(checkFCC(hexU("0041 030A 0327"))), 'NO'); # A+ring+cedilla
108ok(answer(checkFCC(hexU("00C5 0327"))), 'NO'); # A-ring+cedilla
82e740b6 109ok(answer(checkFCC("\x{AC01}\x{1100}\x{1161}")), 'MAYBE'); # hangul
110ok(answer(checkFCC("\x{212B}\x{F900}")), 'NO'); # compat
2b8d773d 111ok(answer(checkFCC("\x{212B}\x{0327}")), 'NO'); # compat
112ok(answer(checkFCC("\x{0327}\x{212B}")), 'NO'); # compat
82e740b6 113