use of android.icu.lang.UScript.ScriptUsage in project j2objc by google.
the class TestUScript method TestScriptMetadata.
@Test
public void TestScriptMetadata() {
UnicodeSet rtl = new UnicodeSet("[[:bc=R:][:bc=AL:]-[:Cn:]-[:sc=Common:]]");
// So far, sample characters are uppercase.
// Georgian is special.
UnicodeSet cased = new UnicodeSet("[[:Lu:]-[:sc=Common:]-[:sc=Geor:]]");
for (int sc = 0; sc < UScript.CODE_LIMIT; ++sc) {
String sn = UScript.getShortName(sc);
ScriptUsage usage = UScript.getUsage(sc);
String sample = UScript.getSampleString(sc);
UnicodeSet scriptSet = new UnicodeSet();
scriptSet.applyIntPropertyValue(UProperty.SCRIPT, sc);
if (usage == ScriptUsage.NOT_ENCODED) {
// Java 6: sample.isEmpty()
assertTrue(sn + " not encoded, no sample", sample.length() == 0);
assertFalse(sn + " not encoded, not RTL", UScript.isRightToLeft(sc));
assertFalse(sn + " not encoded, not LB letters", UScript.breaksBetweenLetters(sc));
assertFalse(sn + " not encoded, not cased", UScript.isCased(sc));
assertTrue(sn + " not encoded, no characters", scriptSet.isEmpty());
} else {
// Java 6: sample.isEmpty()
assertFalse(sn + " encoded, has a sample character", sample.length() == 0);
int firstChar = sample.codePointAt(0);
int charScript = getCharScript(sc);
assertEquals(sn + " script(sample(script))", charScript, UScript.getScript(firstChar));
assertEquals(sn + " RTL vs. set", rtl.contains(firstChar), UScript.isRightToLeft(sc));
assertEquals(sn + " cased vs. set", cased.contains(firstChar), UScript.isCased(sc));
assertEquals(sn + " encoded, has characters", sc == charScript, !scriptSet.isEmpty());
if (UScript.isRightToLeft(sc)) {
rtl.removeAll(scriptSet);
}
if (UScript.isCased(sc)) {
cased.removeAll(scriptSet);
}
}
}
assertEquals("no remaining RTL characters", "[]", rtl.toPattern(true));
assertEquals("no remaining cased characters", "[]", cased.toPattern(true));
assertTrue("Hani breaks between letters", UScript.breaksBetweenLetters(UScript.HAN));
assertTrue("Thai breaks between letters", UScript.breaksBetweenLetters(UScript.THAI));
assertFalse("Latn does not break between letters", UScript.breaksBetweenLetters(UScript.LATIN));
}
Aggregations