use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestExpansion.
@Test
public void TestExpansion() {
String[] testrules = { /*
* This seems to have tested that M was not mapped to an expansion.
* I believe the old builder just did that because it computed the extension CEs
* at the very end, which was a bug.
* Among other problems, it violated the core tailoring principle
* by making an earlier rule depend on a later one.
* And, of course, if M did not get an expansion, then it was primary different from K,
* unlike what the rule &K<<M says.
"&J << K / B & K << M",
*/
"&J << K / B << M" };
String[] testdata = { "JA", "MA", "KA", "KC", "JC", "MC" };
Collator coll;
for (int i = 0; i < testrules.length; i++) {
// logln("Rule " + testrules[i] + " for testing\n");
String rule = testrules[i];
try {
coll = new RuleBasedCollator(rule);
} catch (Exception e) {
warnln("Collator creation failed " + testrules[i]);
return;
}
for (int j = 0; j < 5; j++) {
CollationTest.doTest(this, (RuleBasedCollator) coll, testdata[j], testdata[j + 1], -1);
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestJ3347.
@Test
public void TestJ3347() {
try {
Collator coll = Collator.getInstance(Locale.FRENCH);
((RuleBasedCollator) coll).setAlternateHandlingShifted(true);
if (coll.compare("6", "!6") != 0) {
errln("Jitterbug 3347 failed");
}
} catch (Exception e) {
warnln("Error creating UCA collator");
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method doTestCollation.
/**
* Convenient function to test collation rules.
* @param testCases
* @param rules Collation rules in ICU format. All the strings in this
* array represent the same rule, expressed in different forms.
*/
private void doTestCollation(OneTestCase[] testCases, String[] rules) {
Collator myCollation;
for (String rule : rules) {
try {
myCollation = new RuleBasedCollator(rule);
} catch (Exception e) {
warnln("ERROR: in creation of rule based collator: " + e);
return;
}
myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
myCollation.setStrength(Collator.TERTIARY);
for (OneTestCase testCase : testCases) {
CollationTest.doTest(this, (RuleBasedCollator) myCollation, testCase.m_source_, testCase.m_target_, testCase.m_result_);
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestShifted.
/**
* Jitterbug 2726
*/
@Test
public void TestShifted() {
RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance();
collator.setStrength(Collator.PRIMARY);
collator.setAlternateHandlingShifted(true);
// works properly
CollationTest.doTest(this, collator, " a", "a", 0);
// inconsistent results
CollationTest.doTest(this, collator, "a", "a ", 0);
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestMaxVariable.
// ported from cmsccoll.c
@Test
public void TestMaxVariable() {
int oldMax, max;
String empty = "";
String space = " ";
String dot = ".";
/* punctuation */
String degree = "\u00b0";
/* symbol */
String dollar = "$";
/* currency symbol */
String zero = "0";
/* digit */
Collator coll = Collator.getInstance(ULocale.ROOT);
oldMax = coll.getMaxVariable();
logln(String.format("coll.getMaxVariable(root) -> %04x", oldMax));
((RuleBasedCollator) coll).setAlternateHandlingShifted(true);
coll.setMaxVariable(Collator.ReorderCodes.SPACE);
max = coll.getMaxVariable();
logln(String.format("coll.setMaxVariable(space) -> %04x", max));
if (max != Collator.ReorderCodes.SPACE || !coll.equals(empty, space) || coll.equals(empty, dot) || coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(space, dot) >= 0) {
errln("coll.setMaxVariable(space) did not work");
}
coll.setMaxVariable(Collator.ReorderCodes.PUNCTUATION);
max = coll.getMaxVariable();
logln(String.format("coll.setMaxVariable(punctuation) -> %04x", max));
if (max != Collator.ReorderCodes.PUNCTUATION || !coll.equals(empty, space) || !coll.equals(empty, dot) || coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(dot, degree) >= 0) {
errln("coll.setMaxVariable(punctuation) did not work");
}
coll.setMaxVariable(Collator.ReorderCodes.SYMBOL);
max = coll.getMaxVariable();
logln(String.format("coll.setMaxVariable(symbol) -> %04x", max));
if (max != Collator.ReorderCodes.SYMBOL || !coll.equals(empty, space) || !coll.equals(empty, dot) || !coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(degree, dollar) >= 0) {
errln("coll.setMaxVariable(symbol) did not work");
}
coll.setMaxVariable(Collator.ReorderCodes.CURRENCY);
max = coll.getMaxVariable();
logln(String.format("coll.setMaxVariable(currency) -> %04x", max));
if (max != Collator.ReorderCodes.CURRENCY || !coll.equals(empty, space) || !coll.equals(empty, dot) || !coll.equals(empty, degree) || !coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(dollar, zero) >= 0) {
errln("coll.setMaxVariable(currency) did not work");
}
logln("Test restoring maxVariable");
coll.setMaxVariable(oldMax);
if (oldMax != coll.getMaxVariable()) {
errln("Couldn't restore old maxVariable");
}
}
Aggregations