use of android.icu.text.Collator in project j2objc by google.
the class CollationAPITest method TestSetDecomposition.
/*
* Tests the method public void setDecomposition(int decomposition)
*/
@Test
public void TestSetDecomposition() {
// Tests when if ((decomposition != NO_DECOMPOSITION) && ...) is true
int[] cases = { 0, 1, 14, 15, 18, 19 };
for (int i = 0; i < cases.length; i++) {
try {
// Assuming -1 is not one of the values
Collator c = Collator.getInstance();
c.setDecomposition(cases[i]);
errln("Collator.setDecomposition(int) is suppose to return " + "an exception for an invalid decomposition value of " + cases[i]);
} catch (Exception e) {
}
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method doTestOneReorderingAPITestCase.
/*
* Utility function to test one collation reordering test case.
* @param testcases Array of test cases.
* @param n_testcases Size of the array testcases.
* @param str_rules Array of rules. These rules should be specifying the same rule in different formats.
* @param n_rules Size of the array str_rules.
*/
private void doTestOneReorderingAPITestCase(OneTestCase[] testCases, int[] reorderTokens) {
Collator myCollation = Collator.getInstance(ULocale.ENGLISH);
myCollation.setReorderCodes(reorderTokens);
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 TestFrozeness.
@Test
public void TestFrozeness() {
Collator myCollation = Collator.getInstance(ULocale.CANADA);
boolean exceptionCaught = false;
myCollation.freeze();
assertTrue("Collator not frozen.", myCollation.isFrozen());
try {
myCollation.setStrength(Collator.SECONDARY);
} catch (UnsupportedOperationException e) {
// expected
exceptionCaught = true;
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
try {
myCollation.setReorderCodes(ReorderCodes.DEFAULT);
} catch (UnsupportedOperationException e) {
// expected
exceptionCaught = true;
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
try {
myCollation.setVariableTop(12);
} catch (UnsupportedOperationException e) {
// expected
exceptionCaught = true;
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
Collator myClone = null;
try {
myClone = (Collator) myCollation.clone();
} catch (CloneNotSupportedException e) {
// should not happen - clone is implemented in Collator
errln("ERROR: unable to clone collator.");
}
assertTrue("Clone not frozen as expected.", myClone.isFrozen());
myClone = myClone.cloneAsThawed();
assertFalse("Clone not thawed as expected.", myClone.isFrozen());
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestInvalidListsAndRanges.
@Test
public void TestInvalidListsAndRanges() {
String[] invalidRules = new String[] { // Range not in starred expression
"&\u4e00<\ufffb-'\ud800\udc02'", // Range without start
"&a<*-c", // Range without end
"&a<*b-", // More than one hyphen
"&a<*b-g-l", // Range in the wrong order
"&a<*k-b" };
for (String rule : invalidRules) {
try {
Collator myCollation = new RuleBasedCollator(rule);
warnln("ERROR: Creation of collator didn't fail for " + rule + " when it should.");
CollationTest.doTest(this, (RuleBasedCollator) myCollation, "x", "y", -1);
} catch (Exception e) {
continue;
}
throw new IllegalArgumentException("ERROR: Invalid collator with rule " + rule + " worked fine.");
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMiscTest method TestTibetanConformance.
@Test
public void TestTibetanConformance() {
String[] test = { "\u0FB2\u0591\u0F71\u0061", "\u0FB2\u0F71\u0061" };
try {
Collator coll = Collator.getInstance();
coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
if (coll.compare(test[0], test[1]) != 0) {
errln("Tibetan comparison error");
}
CollationTest.doTest(this, (RuleBasedCollator) coll, test[0], test[1], 0);
} catch (Exception e) {
warnln("Error creating UCA collator");
}
}
Aggregations