use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestBocsuCoverage.
@Test
public void TestBocsuCoverage() {
String test = "\u0041\u0441\u4441\\U00044441\u4441\u0441\u0041";
Collator coll = Collator.getInstance();
coll.setStrength(Collator.IDENTICAL);
CollationKey key = coll.getCollationKey(test);
logln("source:" + key.getSourceString());
}
use of android.icu.text.Collator 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.Collator 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");
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationRegressionTest method Test4092260.
// @bug 4092260
//
// Mu/micro conflict
// Micro symbol and greek lowercase letter Mu should sort identically
//
@Test
public void Test4092260() /* char* par */
{
Locale el = new Locale("el", "");
Collator c = null;
try {
c = Collator.getInstance(el);
} catch (Exception e) {
errln("Failed to create collator for el locale.");
return;
}
// These now have tertiary differences in UCA
c.setStrength(Collator.SECONDARY);
String[] tests = { "\u00B5", "\u003d", "\u03BC" };
compareArray(c, tests);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationRegressionTest method Test4141640.
// @bug 4141640
//
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
//
@Test
public void Test4141640() /* char* par */
{
//
// Rather than just creating a Swedish collator, we might as well
// try to instantiate one for every locale available on the system
// in order to prevent this sort of bug from cropping up in the future
//
Locale[] locales = Collator.getAvailableLocales();
for (int i = 0; i < locales.length; i += 1) {
Collator c = null;
try {
c = Collator.getInstance(locales[i]);
logln("source: " + c.getStrength());
} catch (Exception e) {
String msg = "";
msg += "Could not create collator for locale ";
msg += locales[i].getDisplayName();
errln(msg);
}
}
}
Aggregations