use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestAnyX.
/**
* Test the Any-X transliterators.
*/
@Test
public void TestAnyX() {
Transliterator anyLatin = Transliterator.getInstance("Any-Latin", Transliterator.FORWARD);
expect(anyLatin, "greek:\u03B1\u03B2\u03BA\u0391\u0392\u039A hiragana:\u3042\u3076\u304F cyrillic:\u0430\u0431\u0446", "greek:abkABK hiragana:abuku cyrillic:abc");
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestInstantiation.
// Android-changed: increase timeout.
@Test(timeout = 3000000L)
public void TestInstantiation() {
long ms = System.currentTimeMillis();
String ID;
for (Enumeration e = Transliterator.getAvailableIDs(); e.hasMoreElements(); ) {
ID = (String) e.nextElement();
if (ID.equals("Latin-Han/definition")) {
System.out.println("\nTODO: disabling Latin-Han/definition check for now: fix later");
continue;
}
Transliterator t = null;
try {
t = Transliterator.getInstance(ID);
// This is only true for some subclasses
// // We should get a new instance if we try again
// Transliterator t2 = Transliterator.getInstance(ID);
// if (t != t2) {
// logln("OK: " + Transliterator.getDisplayName(ID) + " (" + ID + "): " + t);
// } else {
// errln("FAIL: " + ID + " returned identical instances");
// t = null;
// }
} catch (IllegalArgumentException ex) {
errln("FAIL: " + ID);
throw ex;
}
if (t != null) {
// Now test toRules
String rules = null;
try {
rules = t.toRules(true);
Transliterator.createFromRules("x", rules, Transliterator.FORWARD);
} catch (IllegalArgumentException ex2) {
errln("FAIL: " + ID + ".toRules() => bad rules: " + rules);
throw ex2;
}
}
}
// Now test the failure path
try {
ID = "<Not a valid Transliterator ID>";
Transliterator t = Transliterator.getInstance(ID);
errln("FAIL: " + ID + " returned " + t);
} catch (IllegalArgumentException ex) {
logln("OK: Bogus ID handled properly");
}
ms = System.currentTimeMillis() - ms;
logln("Elapsed time: " + ms + " ms");
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestDisplayName.
/**
* Make sure display names of variants look reasonable.
*/
@Test
public void TestDisplayName() {
String[] DATA = { // Basic test
"Any-Hex", "Any to Hex Escape", "Hex Escape to Any", // Variants
"Any-Hex/Perl", "Any to Hex Escape/Perl", "Hex Escape to Any/Perl", // Target-only IDs
"NFC", "Any to NFC", "Any to NFD" };
Locale US = Locale.US;
for (int i = 0; i < DATA.length; i += 3) {
String name = Transliterator.getDisplayName(DATA[i], US);
if (!name.equals(DATA[i + 1])) {
errln("FAIL: " + DATA[i] + ".getDisplayName() => " + name + ", expected " + DATA[i + 1]);
} else {
logln("Ok: " + DATA[i] + ".getDisplayName() => " + name);
}
Transliterator t = Transliterator.getInstance(DATA[i], Transliterator.REVERSE);
name = Transliterator.getDisplayName(t.getID(), US);
if (!name.equals(DATA[i + 2])) {
errln("FAIL: " + t.getID() + ".getDisplayName() => " + name + ", expected " + DATA[i + 2]);
} else {
logln("Ok: " + t.getID() + ".getDisplayName() => " + name);
}
// Cover getDisplayName(String)
ULocale save = ULocale.getDefault();
ULocale.setDefault(ULocale.US);
String name2 = Transliterator.getDisplayName(t.getID());
if (!name.equals(name2))
errln("FAIL: getDisplayName with default locale failed");
ULocale.setDefault(save);
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestInvalidBackRef.
@Test
public void TestInvalidBackRef() {
String rule = ". > $1;";
String rule2 = "(.) <> &hex/unicode($1) &name($1); . > $1; [{}] >\u0020;";
try {
Transliterator t = Transliterator.createFromRules("Test", rule, Transliterator.FORWARD);
if (t != null) {
errln("FAIL: createFromRules should have returned NULL");
}
errln("FAIL: Ok: . > $1; => no error");
Transliterator t2 = Transliterator.createFromRules("Test2", rule2, Transliterator.FORWARD);
if (t2 != null) {
errln("FAIL: createFromRules should have returned NULL");
}
errln("FAIL: Ok: . > $1; => no error");
} catch (IllegalArgumentException e) {
logln("Ok: . > $1; => " + e.getMessage());
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestScriptAllCodepoints.
/**
* This test is not in trnstst.cpp. This test has been moved from com/ibm/icu/dev/test/lang/TestUScript.java
* during ICU4J modularization to remove dependency of tests on Transliterator.
*/
@Test
public void TestScriptAllCodepoints() {
int code;
HashSet scriptIdsChecked = new HashSet();
HashSet scriptAbbrsChecked = new HashSet();
for (int i = 0; i <= 0x10ffff; i++) {
code = UScript.getScript(i);
if (code == UScript.INVALID_CODE) {
errln("UScript.getScript for codepoint 0x" + hex(i) + " failed");
}
String id = UScript.getName(code);
String abbr = UScript.getShortName(code);
if (!scriptIdsChecked.contains(id)) {
scriptIdsChecked.add(id);
String newId = "[:" + id + ":];NFD";
try {
Transliterator t = Transliterator.getInstance(newId);
if (t == null) {
errln("Failed to create transliterator for " + hex(i) + " script code: " + id);
}
} catch (Exception e) {
errln("Failed to create transliterator for " + hex(i) + " script code: " + id + " Exception: " + e.getMessage());
}
}
if (!scriptAbbrsChecked.contains(abbr)) {
scriptAbbrsChecked.add(abbr);
String newAbbrId = "[:" + abbr + ":];NFD";
try {
Transliterator t = Transliterator.getInstance(newAbbrId);
if (t == null) {
errln("Failed to create transliterator for " + hex(i) + " script code: " + abbr);
}
} catch (Exception e) {
errln("Failed to create transliterator for " + hex(i) + " script code: " + abbr + " Exception: " + e.getMessage());
}
}
}
}
Aggregations