import java.util.Set;
import java.util.TreeSet;
-import org.junit.Ignore;
import org.junit.Test;
import com.ibm.icu.dev.test.TestFmwk;
}
}
- // TODO(junit): not running before
- @Ignore
@Test
- public void DontTestJ831() { // Latvian does not use upper first
+ public void TestUpperCaseFirst() {
String[] data = {
"I",
"i",
"Y",
"y"
};
- genericLocaleStarter(new Locale("lv", ""), data);
+ genericLocaleStarter(new Locale("da", ""), data);
}
@Test
"\u0663\u0662",
"\u0663\u0663"
};
-
+
//Additional tests to cover bug reported in #9476
String lastDigitDifferent[]={"2004","2005",
"110005", "110006",
preZeroTestStrings[j],0);
}
}
-
+
//Testing that the behavior reported in #9476 is fixed
//We expect comparisons between adjacent pairs will result in -1
for (int i=0; i < lastDigitDifferent.length -1; i=i+2 ) {
CollationTest.doTest(this, coll, lastDigitDifferent[i], lastDigitDifferent[i+1], -1);
}
-
+
//cover setNumericCollationDefault, getNumericCollation
assertTrue("The Numeric Collation setting is on", coll.getNumericCollation());
};
doTestCollation(m_rangeTestCases_, rules);
}
-
+
@Test
public void TestSameStrengthListQuoted() {
String[] rules = new String[] {
};
doTestCollation(testCases, rules);
}
-
+
@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",
};
"x",
"y",
-1);
-
+
} catch (Exception e) {
continue;
}
// These are working as expected.
"&';'<'+'<','<'-'<'&'<''<'*'<' '",
- // List. Desired rule is
+ // List. Desired rule is
// "&';'<*'+,-&''* '",
// but it doesn't work. Instead, '' should be outside quotes as below.
"&';'<*'+,-&''''* '",
//"&';'<*'+'-'-&'\\u0027'* '",
// The following rules are not working.
- // "&';'<'+'<','<'-'<'&'<\\u0027<'*'<' '",
+ // "&';'<'+'<','<'-'<'&'<\\u0027<'*'<' '",
//"&'\u003b'<'\u002b'<'\u002c'<'\u002d'<'\u0026'<'\u0027'<\u002a'<'\u0020'",
//"&'\u003b'<'\u002b'<'\u002c'<'\u002d'<'\u0026'<\\u0027<\u002a'<'\u0020'",
};
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 */
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 = "
+ 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]);
}
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 = "
+ 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]);
}
}
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.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);
}
- }
+ }
}
/*
/* 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);
+ 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[]{});
+ 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 });
+ myCollation.setReorderCodes(new int[]{ ReorderCodes.NONE });
retrievedReorderCodes = myCollation.getReorderCodes();
if (retrievedReorderCodes.length != 0) {
errln("ERROR: [NONE] retrieved reorder codes was not null.");
gotException = true;
}
if (!gotException) {
- errln("ERROR: exception was not thrown for illegal reorder codes argument.");
+ errln("ERROR: exception was not thrown for illegal reorder codes argument.");
}
-
+
/* set duplicate reorder codes */
gotException = false;
try {
gotException = true;
}
if (!gotException) {
- errln("ERROR: reorder codes following a 'default' code should have thrown an exception but did not.");
+ errln("ERROR: reorder codes following a 'default' code should have thrown an exception but did not.");
}
}
-
+
/*
* Test reordering API.
*/
int[] reorderCodes = {UScript.GREEK, UScript.HAN, ReorderCodes.PUNCTUATION};
int[] retrievedReorderCodes;
-
+
/* build collator tertiary */
myCollation = new RuleBasedCollator(rules);
myCollation.setStrength(Collator.TERTIARY);
if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
}
-
+
/* clear the reordering */
- myCollation.setReorderCodes(null);
+ 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);
+ myCollation.setReorderCodes(ReorderCodes.DEFAULT);
retrievedReorderCodes = myCollation.getReorderCodes();
if (!Arrays.equals(rulesReorderCodes, retrievedReorderCodes)) {
errln("ERROR: retrieved reorder codes do not match set reorder codes.");
"expected 2, was = " + equivalentScripts.length);
}
}
-
+
@Test
public void TestGreekFirstReorderCloning() {
String[] testSourceCases = {
myCollation.setStrength(Collator.TERTIARY);
for (int i = 0; i < testSourceCases.length ; i++)
{
- CollationTest.doTest(this, (RuleBasedCollator)myCollation,
- testSourceCases[i], testTargetCases[i],
+ CollationTest.doTest(this, (RuleBasedCollator)myCollation,
+ testSourceCases[i], testTargetCases[i],
results[i]);
}
}
{
Collator myCollation = Collator.getInstance(ULocale.ENGLISH);
myCollation.setReorderCodes(reorderTokens);
-
+
for (OneTestCase testCase : testCases) {
CollationTest.doTest(this, (RuleBasedCollator)myCollation,
testCase.m_source_,
int[] apiRules = {
UScript.GREEK
};
-
+
OneTestCase[] privateUseCharacterStrings = {
new OneTestCase("\u0391", "\u0391", 0),
new OneTestCase("\u0041", "\u0391", 1),
int[] apiRules = {
UScript.UNKNOWN, UScript.GREEK
};
-
+
OneTestCase[] privateUseCharacterStrings = {
new OneTestCase("\u0391", "\u0391", 0),
new OneTestCase("\u0041", "\u0391", -1),
new OneTestCase("\u0060", "\u0391", -1),
new OneTestCase("\u0391", "\ue2dc", 1),
};
-
+
/* Test rules creation */
doTestCollation(privateUseCharacterStrings, strRules);
new OneTestCase("\u0060", "\u0391", 1),
new OneTestCase("\u0024", "\u0041", 1),
};
-
+
/* Test rules creation */
doTestCollation(privateUseCharacterStrings, strRules);
new OneTestCase("\ufa27", "\u0041", -1),
new OneTestCase("\uD869\uDF00", "\u0041", -1),
};
-
+
/* Test rules creation */
doTestCollation(privateUseCharacterStrings, strRules);
/* Test collation reordering API */
doTestOneReorderingAPITestCase(privateUseCharacterStrings, apiRules);
}
-
+
@Test
public void TestHaniReorderWithOtherRules()
{
new OneTestCase("\uD869\uDF00", "\u0041", -1),
new OneTestCase("b", "a", -1),
};
-
+
/* Test rules creation */
doTestCollation(privateUseCharacterStrings, strRules);
}
-
+
@Test
public void TestMultipleReorder()
{
int[] apiRules = {
UScript.GREEK, UScript.UNKNOWN, ReorderCodes.DIGIT, UScript.LATIN, UScript.HAN
};
-
+
OneTestCase[] collationTestCases = {
new OneTestCase("\u0391", "\u0041", -1),
new OneTestCase("\u0031", "\u0041", -1),
/* Test collation reordering API */
doTestOneReorderingAPITestCase(collationTestCases, apiRules);
}
-
+
@Test
public void TestFrozeness()
{
Collator myCollation = Collator.getInstance(ULocale.CANADA);
boolean exceptionCaught = false;
-
+
myCollation.freeze();
assertTrue("Collator not frozen.", myCollation.isFrozen());
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
-
+
try {
myCollation.setReorderCodes(ReorderCodes.DEFAULT);
} catch (UnsupportedOperationException e) {
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
-
+
try {
myCollation.setVariableTop(12);
} catch (UnsupportedOperationException e) {
}
assertTrue("Frozen collator allowed change.", exceptionCaught);
exceptionCaught = false;
-
+
Collator myClone = null;
try {
myClone = (Collator) myCollation.clone();
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());
+ assertFalse("Clone not thawed as expected.", myClone.isFrozen());
}
// Test case for Ticket#9409