use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestFunkyA.
@Test
public void TestFunkyA() {
String[] testSourceCases = { "\u0041\u0300\u0301", "\u0041\u0300\u0316", "\u0041\u0300", "\u00C0\u0301", // this would work with forced normalization
"\u00C0\u0316" };
String[] testTargetCases = { "\u0041\u0301\u0300", "\u0041\u0316\u0300", "\u00C0", "\u0041\u0301\u0300", // this would work with forced normalization
"\u0041\u0316\u0300" };
int[] results = { 1, 0, 0, 1, 0 };
Collator myCollation;
try {
myCollation = Collator.getInstance(new Locale("en", "US"));
} catch (Exception e) {
warnln("ERROR: in creation of rule based collator");
return;
}
// logln("Testing some A letters, for some reason");
myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
myCollation.setStrength(Collator.TERTIARY);
for (int i = 0; i < 4; i++) {
CollationTest.doTest(this, (RuleBasedCollator) myCollation, testSourceCases[i], testTargetCases[i], results[i]);
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestContractionEndCompare.
@Test
public void TestContractionEndCompare() {
String rules = "&b=ch";
String src = "bec";
String tgt = "bech";
Collator coll = null;
try {
coll = new RuleBasedCollator(rules);
} catch (Exception e) {
warnln("Collator creation failed " + rules);
return;
}
CollationTest.doTest(this, (RuleBasedCollator) coll, src, tgt, 1);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestBeforeRuleWithScriptReordering.
/*
* This test ensures that characters placed before a character in a different script have the same lead byte
* in their collation key before and after script reordering.
*/
@Test
public void TestBeforeRuleWithScriptReordering() throws Exception {
/* build collator */
String rules = "&[before 1]\u03b1 < \u0e01";
int[] reorderCodes = { UScript.GREEK };
int result;
Collator myCollation = new RuleBasedCollator(rules);
myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
myCollation.setStrength(Collator.TERTIARY);
String base = "\u03b1";
/* base */
String before = "\u0e01";
/* ko kai */
/* check collation results - before rule applied but not script reordering */
result = myCollation.compare(base, before);
if (!(result > 0)) {
errln("Collation result not correct before script reordering.");
}
/* check the lead byte of the collation keys before script reordering */
CollationKey baseKey = myCollation.getCollationKey(base);
CollationKey beforeKey = myCollation.getCollationKey(before);
byte[] baseKeyBytes = baseKey.toByteArray();
byte[] beforeKeyBytes = beforeKey.toByteArray();
if (baseKeyBytes[0] != beforeKeyBytes[0]) {
errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = " + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
}
/* reorder the scripts */
myCollation.setReorderCodes(reorderCodes);
/* check collation results - before rule applied and after script reordering */
result = myCollation.compare(base, before);
if (!(result > 0)) {
errln("Collation result not correct after script reordering.");
}
/* check the lead byte of the collation keys after script reordering */
baseKey = myCollation.getCollationKey(base);
beforeKey = myCollation.getCollationKey(before);
baseKeyBytes = baseKey.toByteArray();
beforeKeyBytes = beforeKey.toByteArray();
if (baseKeyBytes[0] != beforeKeyBytes[0]) {
errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = " + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestFCDProblem.
@Test
public void TestFCDProblem() {
String s1 = "\u0430\u0306\u0325";
String s2 = "\u04D1\u0325";
Collator coll = null;
try {
coll = Collator.getInstance();
} catch (Exception e) {
warnln("Can't create collator");
return;
}
coll.setDecomposition(Collator.NO_DECOMPOSITION);
CollationTest.doTest(this, (RuleBasedCollator) coll, s1, s2, 0);
coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
CollationTest.doTest(this, (RuleBasedCollator) coll, s1, s2, 0);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationRegressionTest method Test4124632.
// @bug 4124632
//
// Collator::getCollationKey was hanging on certain character sequences
//
@Test
public void Test4124632() /* char* par */
{
Collator coll = null;
try {
coll = Collator.getInstance(Locale.JAPAN);
} catch (Exception e) {
errln("Failed to create collator for Locale::JAPAN");
return;
}
String test = "\u0041\u0308\u0062\u0063";
CollationKey key;
try {
key = coll.getCollationKey(test);
logln(key.getSourceString());
} catch (Exception e) {
errln("CollationKey creation failed.");
}
}
Aggregations