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