1 package org.unicode.cldr.unittest; 2 3 import java.util.Arrays; 4 import java.util.BitSet; 5 import java.util.Set; 6 7 import org.unicode.cldr.draft.IdentifierInfo; 8 import org.unicode.cldr.draft.IdentifierInfo.IdentifierStatus; 9 10 import com.ibm.icu.dev.test.TestFmwk; 11 import com.ibm.icu.text.UnicodeSet; 12 13 public class TestIdentifierInfo extends TestFmwk { 14 main(String[] args)15 public static void main(String[] args) { 16 new TestIdentifierInfo().run(args); 17 } 18 TestMain()19 public void TestMain() { 20 String[][] testCases = { 21 // Format is testString, expected scripts, expected alternates, 22 // expected numerics (if any) 23 { "ab c", "ASCII", "Latn Common" }, 24 { "a12", "ASCII", "Common Latn", "", "[0]" }, 25 { "ー", "HIGHLY_RESTRICTIVE", "", "Kana Hira" }, 26 { "カー", "HIGHLY_RESTRICTIVE", "Kana" }, 27 { "ーカ", "HIGHLY_RESTRICTIVE", "Kana" }, 28 { "かー", "HIGHLY_RESTRICTIVE", "Hira" }, 29 { "ーか", "HIGHLY_RESTRICTIVE", "Hira" }, 30 { "かーカa", "HIGHLY_RESTRICTIVE", "Kana Hira Latn" }, 31 { "a、 〃", "HIGHLY_RESTRICTIVE", "Zyyy Latn", 32 "Bopo Hani Hang Hira Kana" }, 33 { "a、 〃カ一", "HIGHLY_RESTRICTIVE", "Zyyy Latn Kana Hani" }, 34 { "a가一", "HIGHLY_RESTRICTIVE", "Hani Hang Latn" }, 35 { "aㄅ一", "HIGHLY_RESTRICTIVE", "Bopo Hani Latn" }, 36 { "٢", "HIGHLY_RESTRICTIVE", "", "Arab Thaa", "[٠]" }, 37 { "٢\u0670", "HIGHLY_RESTRICTIVE", "", "Arab Thaa; Arab Syrc", 38 "[٠]" }, 39 { "٢\u0670ـ", "HIGHLY_RESTRICTIVE", "", "Arab Thaa; Arab Syrc", 40 "[٠]" }, 41 { "٢\u0670ـ،", "HIGHLY_RESTRICTIVE", "", 42 "Arab Thaa; Arab Syrc", "[٠]" }, 43 { "AᎪ", "MINIMALLY_RESTRICTIVE", "Cher Latn" }, 44 { "aА가一", "MINIMALLY_RESTRICTIVE", "Cyrl Hani Hang Latn" }, 45 { "AᎪА♥", "MINIMALLY_RESTRICTIVE", "Zyyy Cher Cyrl Latn" }, 46 { "a1२", "UNRESTRICTIVE", "Zyyy Latn", "Deva Kthi Mahj Dogr", "[0०]" }, 47 { "a1٢", "UNRESTRICTIVE", "Zyyy Latn", "Arab Thaa", "[0٠]" }, }; 48 IdentifierInfo actualInfo = new IdentifierInfo(); 49 50 int item = 0; 51 for (String[] testCase : testCases) { 52 ++item; 53 final String identifier = testCase[0]; 54 final String actualStatusString = testCase[1]; 55 final String scriptsString = testCase[2]; 56 final String multiscriptsString = testCase.length < 4 ? "" 57 : testCase[3]; 58 final String numericString = testCase.length < 5 ? "[]" 59 : testCase[4]; 60 61 actualInfo.setIdentifier(identifier); 62 IdentifierStatus actualStatus = actualInfo.getRestrictionLevel(); 63 IdentifierStatus expectedStatus = IdentifierStatus 64 .valueOf(actualStatusString); 65 66 BitSet expectedScripts = IdentifierInfo.parseScripts(scriptsString); 67 Set<BitSet> expectedMultiscripts = IdentifierInfo 68 .parseAlternates(multiscriptsString); 69 UnicodeSet expectedNumerics = new UnicodeSet(numericString); 70 71 if (!actualInfo.getScripts().equals(expectedScripts) 72 || !actualStatus.equals(expectedStatus) 73 || !actualInfo.getAlternates().equals(expectedMultiscripts) 74 || !actualInfo.getNumerics().equals(expectedNumerics)) { 75 errln("(" + item + ") " + Arrays.asList(testCase) + " !=" 76 + actualInfo); 77 } 78 } 79 } 80 81 } 82