use of android.icu.text.UnicodeSet in project j2objc by google.
the class AnyScriptTest method TestCommonDigits.
@Test
public void TestCommonDigits() {
UnicodeSet westernDigitSet = new UnicodeSet("[0-9]");
UnicodeSet westernDigitSetAndMarks = new UnicodeSet("[[0-9][:Mn:]]");
UnicodeSet arabicDigitSet = new UnicodeSet("[[:Nd:]&[:block=Arabic:]]");
Transliterator latin = Transliterator.getInstance("Any-Latn");
Transliterator arabic = Transliterator.getInstance("Any-Arabic");
String westernDigits = getList(westernDigitSet);
String arabicDigits = getList(arabicDigitSet);
String fromArabic = latin.transform(arabicDigits);
assertContainsAll("Any-Latin transforms Arabic digits", westernDigitSetAndMarks, fromArabic);
if (false) {
// we don't require conversion to Arabic digits
String fromLatin = arabic.transform(westernDigits);
assertContainsAll("Any-Arabic transforms Western digits", arabicDigitSet, fromLatin);
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class AnyScriptTest method TestScripts.
@Test
public void TestScripts() {
// get a couple of characters of each script for testing
StringBuffer testBuffer = new StringBuffer();
for (int script = 0; script < UScript.CODE_LIMIT; ++script) {
UnicodeSet test = new UnicodeSet().applyPropertyAlias("script", UScript.getName(script));
int count = Math.min(20, test.size());
for (int i = 0; i < count; ++i) {
testBuffer.append(UTF16.valueOf(test.charAt(i)));
}
}
String test = testBuffer.toString();
logln("Test line: " + test);
int inclusion = TestFmwk.getExhaustiveness();
boolean testedUnavailableScript = false;
for (int script = 0; script < UScript.CODE_LIMIT; ++script) {
if (script == UScript.COMMON || script == UScript.INHERITED) {
continue;
}
// Make sure, however, that we test at least one unavailable script
if (inclusion < 10 && script != UScript.LATIN && script != UScript.HAN && script != UScript.HIRAGANA && testedUnavailableScript) {
continue;
}
// long name
String scriptName = UScript.getName(script);
ULocale locale = new ULocale(scriptName);
if (locale.getLanguage().equals("new") || locale.getLanguage().equals("pau")) {
if (logKnownIssue("11171", "long script name loosely looks like a locale ID with a known likely script")) {
continue;
}
}
Transliterator t;
try {
t = Transliterator.getInstance("any-" + scriptName);
} catch (Exception e) {
testedUnavailableScript = true;
logln("Skipping unavailable: " + scriptName);
// we don't handle all scripts
continue;
}
logln("Checking: " + scriptName);
if (t != null) {
// just verify we don't crash
t.transform(test);
}
// 4-letter script code
String shortScriptName = UScript.getShortName(script);
try {
t = Transliterator.getInstance("any-" + shortScriptName);
} catch (Exception e) {
errln("Transliterator.getInstance() worked for \"any-" + scriptName + "\" but not for \"any-" + shortScriptName + '\"');
}
// just verify we don't crash
t.transform(test);
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class ErrorTest method TestRBTErrors.
// public void TestUniToHexErrors() {
// Transliterator t = null;
// try {
// t = new UnicodeToHexTransliterator("", true, null);
// if (t != null) {
// errln("FAIL: Created a UnicodeToHexTransliterator with an empty pattern.");
// }
// } catch (IllegalArgumentException e) {
// }
// try {
// t = new UnicodeToHexTransliterator("\\x", true, null);
// if (t != null) {
// errln("FAIL: Created a UnicodeToHexTransliterator with a bad pattern.");
// }
// } catch (IllegalArgumentException e) {
// }
// t = new UnicodeToHexTransliterator();
// try {
// ((UnicodeToHexTransliterator) t).applyPattern("\\x");
// errln("FAIL: UnicodeToHexTransliterator::applyPattern succeeded with a bad pattern.");
// } catch (Exception e) {
// }
// }
@Test
public void TestRBTErrors() {
String rules = "ab>y";
String id = "MyRandom-YReverse";
String goodPattern = "[[:L:]&[\\u0000-\\uFFFF]]";
/* all BMP letters */
UnicodeSet set = null;
try {
set = new UnicodeSet(goodPattern);
try {
Transliterator t = Transliterator.createFromRules(id, rules, Transliterator.REVERSE);
t.setFilter(set);
Transliterator.registerClass(id, t.getClass(), null);
Transliterator.unregister(id);
try {
Transliterator.getInstance(id, Transliterator.REVERSE);
errln("FAIL: construction of unregistered ID should have failed.");
} catch (IllegalArgumentException e) {
}
} catch (IllegalArgumentException e) {
errln("FAIL: Was not able to create a good RBT to test registration.");
}
} catch (IllegalArgumentException e) {
errln("FAIL: Was not able to create a good UnicodeSet based on valid patterns.");
return;
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class SpoofCheckerTest method TestGetSetAllowedChars.
/*
* get & setAllowedChars
*/
@Test
public void TestGetSetAllowedChars() {
SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.CHAR_LIMIT).build();
UnicodeSet us;
UnicodeSet uset;
uset = sc.getAllowedChars();
assertTrue("", uset.isFrozen());
us = new UnicodeSet(0x41, 0x5A);
/* [A-Z] */
sc = new SpoofChecker.Builder().setChecks(SpoofChecker.CHAR_LIMIT).setAllowedChars(us).build();
assertEquals("", us, sc.getAllowedChars());
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class SpoofCheckerTest method TestMixedNumbers.
@Test
public void TestMixedNumbers() {
Object[][] tests = { { "1", "[0]" }, { "१", "[०]" }, { "1१", "[0०]" }, { "١۱", "[٠۰]" }, { "a♥", "[]" }, { "a\u303c", "[]" }, { "aー\u303c", "[]" }, { "aー\u303cア", "[]" }, { "アaー\u303c", "[]" }, { "a1١", "[0٠]" }, { "a1١۱", "[0٠۰]" }, { "١ー\u303caア1१۱", "[0٠۰०]" }, { "aアー\u303c1१١۱", "[0٠۰०]" } };
CheckResult checkResult = new CheckResult();
for (Object[] test : tests) {
String testString = (String) test[0];
UnicodeSet expected = new UnicodeSet((String) test[1]);
SpoofChecker sc = new SpoofChecker.Builder().setChecks(// only check this
SpoofChecker.MIXED_NUMBERS).build();
boolean actualValue = sc.failsChecks(testString, checkResult);
assertEquals("", expected, checkResult.numerics);
assertEquals("Testing spoof mixed numbers for '" + testString + "', ", expected.size() > 1, actualValue);
}
}
Aggregations