use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestUnknownCollationKeyword.
// Test case for Ticket#9409
// Unknown collation type should be ignored, without printing stack trace
@Test
public void TestUnknownCollationKeyword() {
Collator coll1 = Collator.getInstance(new ULocale("en_US@collation=bogus"));
Collator coll2 = Collator.getInstance(new ULocale("en_US"));
assertEquals("Unknown collation keyword 'bogus' should be ignored", coll1, coll2);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestReorderingAPIWithRuleCreatedCollator.
/*
* Test reordering API.
*/
@Test
public void TestReorderingAPIWithRuleCreatedCollator() throws Exception {
Collator myCollation;
String rules = "[reorder Hani Grek]";
int[] rulesReorderCodes = { UScript.HAN, UScript.GREEK };
int[] reorderCodes = { UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION };
int[] retrievedReorderCodes;
/* build collator tertiary */
myCollation = new RuleBasedCollator(rules);
myCollation.setStrength(Collator.TERTIARY);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
/* clear the reordering */
myCollation.setReorderCodes(null);
retrievedReorderCodes = myCollation.getReorderCodes();
if (retrievedReorderCodes.length != 0) {
errln("ERROR: retrieved reorder codes was not null.");
}
/* set the reorderding */
myCollation.setReorderCodes(reorderCodes);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
/* reset the reordering */
myCollation.setReorderCodes(ReorderCodes.DEFAULT);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestReorderingAPI.
/*
* Test reordering API.
*/
@Test
public void TestReorderingAPI() throws Exception {
Collator myCollation;
int[] reorderCodes = { UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION };
int[] duplicateReorderCodes = { UScript.HIRAGANA, UScript.GREEK, ReorderCodes.CURRENCY, UScript.KATAKANA };
int[] reorderCodesStartingWithDefault = { ReorderCodes.DEFAULT, UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION };
int[] retrievedReorderCodes;
String greekString = "\u03b1";
String punctuationString = "\u203e";
/* build collator tertiary */
myCollation = new RuleBasedCollator("");
myCollation.setStrength(Collator.TERTIARY);
/* set the reorderding */
myCollation.setReorderCodes(reorderCodes);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
if (!(myCollation.compare(greekString, punctuationString) < 0)) {
errln("ERROR: collation result should have been less.");
}
/* clear the reordering */
myCollation.setReorderCodes(null);
retrievedReorderCodes = myCollation.getReorderCodes();
if (retrievedReorderCodes.length != 0) {
errln("ERROR: retrieved reorder codes was not null.");
}
if (!(myCollation.compare(greekString, punctuationString) > 0)) {
errln("ERROR: collation result should have been greater.");
}
// do it again with an empty but non-null array
/* set the reorderding */
myCollation.setReorderCodes(reorderCodes);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(reorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
if (!(myCollation.compare(greekString, punctuationString) < 0)) {
errln("ERROR: collation result should have been less.");
}
/* clear the reordering */
myCollation.setReorderCodes(new int[] {});
retrievedReorderCodes = myCollation.getReorderCodes();
if (retrievedReorderCodes.length != 0) {
errln("ERROR: retrieved reorder codes was not null.");
}
if (!(myCollation.compare(greekString, punctuationString) > 0)) {
errln("ERROR: collation result should have been greater.");
}
/* clear the reordering using [NONE] */
myCollation.setReorderCodes(new int[] { ReorderCodes.NONE });
retrievedReorderCodes = myCollation.getReorderCodes();
if (retrievedReorderCodes.length != 0) {
errln("ERROR: [NONE] retrieved reorder codes was not null.");
}
boolean gotException = false;
/* set duplicates in the reorder codes */
try {
myCollation.setReorderCodes(duplicateReorderCodes);
} catch (IllegalArgumentException e) {
// expect exception on illegal arguments
gotException = true;
}
if (!gotException) {
errln("ERROR: exception was not thrown for illegal reorder codes argument.");
}
/* set duplicate reorder codes */
gotException = false;
try {
myCollation.setReorderCodes(reorderCodesStartingWithDefault);
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("ERROR: reorder codes following a 'default' code should have thrown an exception but did not.");
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationRegressionTest method Test4095316.
// @bug 4095316
//
@Test
public void Test4095316() /* char* par */
{
Locale el_GR = new Locale("el", "GR");
Collator c = null;
try {
c = Collator.getInstance(el_GR);
} catch (Exception e) {
errln("Failed to create collator for el_GR locale");
return;
}
// These now have tertiary differences in UCA
// c->setStrength(Collator::TERTIARY);
// c->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, status);
c.setStrength(Collator.SECONDARY);
String[] tests = { "\u03D4", "\u003d", "\u03AB" };
compareArray(c, tests);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestNonLeadBytesDuringCollationReordering.
/*
* Test that in a primary-compressed sort key all bytes except the first one are unchanged under script reordering.
*/
@Test
public void TestNonLeadBytesDuringCollationReordering() throws Exception {
Collator myCollation;
byte[] baseKey;
byte[] reorderKey;
int[] reorderCodes = { UScript.GREEK };
String testString = "\u03b1\u03b2\u03b3";
/* build collator tertiary */
myCollation = new RuleBasedCollator("");
myCollation.setStrength(Collator.TERTIARY);
baseKey = myCollation.getCollationKey(testString).toByteArray();
myCollation.setReorderCodes(reorderCodes);
reorderKey = myCollation.getCollationKey(testString).toByteArray();
if (baseKey.length != reorderKey.length) {
errln("Key lengths not the same during reordering.\n");
}
for (int i = 1; i < baseKey.length; i++) {
if (baseKey[i] != reorderKey[i]) {
errln("Collation key bytes not the same at position " + i);
}
}
/* build collator tertiary */
myCollation = new RuleBasedCollator("");
myCollation.setStrength(Collator.QUATERNARY);
baseKey = myCollation.getCollationKey(testString).toByteArray();
myCollation.setReorderCodes(reorderCodes);
reorderKey = myCollation.getCollationKey(testString).toByteArray();
if (baseKey.length != reorderKey.length) {
errln("Key lengths not the same during reordering.\n");
}
for (int i = 1; i < baseKey.length; i++) {
if (baseKey[i] != reorderKey[i]) {
errln("Collation key bytes not the same at position " + i);
}
}
}
Aggregations