use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestLocaleResource.
/**
* Basic test of a locale resource based rule.
*/
@Test
public void TestLocaleResource() {
String[] DATA = { // id from to
"Latin-Greek/UNGEGN", "b", "\u03bc\u03c0", "Latin-el", "b", "\u03bc\u03c0", "Latin-Greek", "b", "\u03B2", "Greek-Latin/UNGEGN", "\u03B2", "v", "el-Latin", "\u03B2", "v", "Greek-Latin", "\u03B2", "b" };
for (int i = 0; i < DATA.length; i += 3) {
Transliterator t = Transliterator.getInstance(DATA[i]);
expect(t, DATA[i + 1], DATA[i + 2]);
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestToRulesMark.
/**
* Mark's toRules test.
*/
@Test
public void TestToRulesMark() {
String testRules = "::[[:Latin:][:Mark:]];" + "::NFKD (NFC);" + "::Lower (Lower);" + // alpha
"a <> \\u03B1;" + "::NFKC (NFD);" + "::Upper (Lower);" + "::Lower ();" + "::([[:Greek:][:Mark:]]);";
String testRulesForward = "::[[:Latin:][:Mark:]];" + "::NFKD(NFC);" + "::Lower(Lower);" + "a > \\u03B1;" + "::NFKC(NFD);" + "::Upper (Lower);" + "::Lower ();";
String testRulesBackward = "::[[:Greek:][:Mark:]];" + "::Lower (Upper);" + "::NFD(NFKC);" + "\\u03B1 > a;" + "::Lower(Lower);" + "::NFC(NFKD);";
// a-acute
String source = "\u00E1";
// alpha-acute
String target = "\u03AC";
Transliterator t2 = Transliterator.createFromRules("source-target", testRules, Transliterator.FORWARD);
Transliterator t3 = Transliterator.createFromRules("target-source", testRules, Transliterator.REVERSE);
expect(t2, source, target);
expect(t3, target, source);
checkRules("Failed toRules FORWARD", t2, testRulesForward);
checkRules("Failed toRules BACKWARD", t3, testRulesBackward);
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestRuleBasedInverse.
/**
* Create some inverses and confirm that they work. We have to be
* careful how we do this, since the inverses will not be true
* inverses -- we can't throw any random string at the composition
* of the transliterators and expect the identity function. F x
* F' != I. However, if we are careful about the input, we will
* get the expected results.
*/
@Test
public void TestRuleBasedInverse() {
String RULES = "abc>zyx;" + "ab>yz;" + "bc>zx;" + "ca>xy;" + "a>x;" + "b>y;" + "c>z;" + "abc<zyx;" + "ab<yz;" + "bc<zx;" + "ca<xy;" + "a<x;" + "b<y;" + "c<z;" + "";
String[] DATA = { // we will be okay though (left, abc; right xyz).
"a", "x", "abcacab", "zyxxxyy", "caccb", "xyzzy" };
Transliterator fwd = Transliterator.createFromRules("<ID>", RULES, Transliterator.FORWARD);
Transliterator rev = Transliterator.createFromRules("<ID>", RULES, Transliterator.REVERSE);
for (int i = 0; i < DATA.length; i += 2) {
expect(fwd, DATA[i], DATA[i + 1]);
expect(rev, DATA[i + 1], DATA[i]);
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestFilterIDs.
/**
* Test filter syntax in IDs. (J23)
*/
@Test
public void TestFilterIDs() {
String[] DATA = { // ID
"[aeiou]Any-Hex", // expected inverse ID
"[aeiou]Hex-Any", // src
"quizzical", // expected ID.translit(src)
"q\\u0075\\u0069zz\\u0069c\\u0061l", "[aeiou]Any-Hex;[^5]Hex-Any", "[^5]Any-Hex;[aeiou]Hex-Any", "quizzical", "q\\u0075izzical", "[abc]Null", "[abc]Null", "xyz", "xyz" };
for (int i = 0; i < DATA.length; i += 4) {
String ID = DATA[i];
Transliterator t = Transliterator.getInstance(ID);
expect(t, DATA[i + 2], DATA[i + 3]);
// Check the ID
if (!ID.equals(t.getID())) {
errln("FAIL: getInstance(" + ID + ").getID() => " + t.getID());
}
// Check the inverse
String uID = DATA[i + 1];
Transliterator u = t.getInverse();
if (u == null) {
errln("FAIL: " + ID + ".getInverse() returned NULL");
} else if (!u.getID().equals(uID)) {
errln("FAIL: " + ID + ".getInverse().getID() => " + u.getID() + ", expected " + uID);
}
}
}
use of android.icu.text.Transliterator in project j2objc by google.
the class TransliteratorTest method TestBeginEndToRules.
@Test
public void TestBeginEndToRules() {
// to (i.e., does the same thing as) the original rule set
for (int i = 0; i < BEGIN_END_TEST_CASES.length; i += 3) {
Transliterator t = Transliterator.createFromRules("--", BEGIN_END_TEST_CASES[i], Transliterator.FORWARD);
String rules = t.toRules(false);
Transliterator t2 = Transliterator.createFromRules("Test case #" + (i / 3), rules, Transliterator.FORWARD);
expect(t2, BEGIN_END_TEST_CASES[i + 1], BEGIN_END_TEST_CASES[i + 2]);
}
// do the same thing for the reversible test case
Transliterator reversed = Transliterator.createFromRules("Reversed", BEGIN_END_RULES[17], Transliterator.REVERSE);
String rules = reversed.toRules(false);
Transliterator reversed2 = Transliterator.createFromRules("Reversed", rules, Transliterator.FORWARD);
expect(reversed2, "xy XY XYZ yz YZ", "xy abc xaba yz aba");
}
Aggregations