summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-04-22 13:38:42 -0700
committerElliott Hughes <enh@google.com>2010-04-22 14:00:53 -0700
commita7d4139bed693bf6037bf5f7f49a24b077102adc (patch)
treedb9d78c4a6cc9478a88996acd08f7b19be0cba48 /luni
parent5779f05dd67ea322017c4ceb45270f5c6969d6b5 (diff)
downloadlibcore-a7d4139bed693bf6037bf5f7f49a24b077102adc.zip
libcore-a7d4139bed693bf6037bf5f7f49a24b077102adc.tar.gz
libcore-a7d4139bed693bf6037bf5f7f49a24b077102adc.tar.bz2
java.text.RuleBasedCollator fixes.
Add expectations for broken harmony tests, add our own equivalent (but correct) tets, and fix the bug turned up by the correct tests: the icu4jni RuleBasedCollator was using toString to convert a CharacterIterator to a String, resulting in iteration over the result of Object.toString (the class name and identity hash code) rather than the characters of interest. Also shut javac up about non-ASCII characters in Locale.java. Bug: 2608742 Bug: 2608750 Change-Id: I2171789058c8116eacd7e5815bd483f0bc07c69b
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/util/Locale.java4
-rw-r--r--luni/src/test/java/java/text/CollatorTest.java61
2 files changed, 63 insertions, 2 deletions
diff --git a/luni/src/main/java/java/util/Locale.java b/luni/src/main/java/java/util/Locale.java
index 7d03eac..c6535c1 100644
--- a/luni/src/main/java/java/util/Locale.java
+++ b/luni/src/main/java/java/util/Locale.java
@@ -392,8 +392,8 @@ public final class Locale implements Cloneable, Serializable {
* to {@code locale}. The exact output form depends on whether this locale
* corresponds to a specific language, country and variant, such as:
* {@code English}, {@code English (United States)}, {@code English (United
- * States,Computer)}, {@code anglais (États-Unis)}, {@code anglais
- * (États-Unis,informatique)}.
+ * States,Computer)}, {@code anglais (&#x00c9;tats-Unis)}, {@code anglais
+ * (&#x00c9;tats-Unis,informatique)}.
*/
public String getDisplayName(Locale locale) {
int count = 0;
diff --git a/luni/src/test/java/java/text/CollatorTest.java b/luni/src/test/java/java/text/CollatorTest.java
index 48c0eb1..5cded0a 100644
--- a/luni/src/test/java/java/text/CollatorTest.java
+++ b/luni/src/test/java/java/text/CollatorTest.java
@@ -82,4 +82,65 @@ public class CollatorTest extends junit.framework.TestCase {
assertTrue("Error: \u00e0\u0325 should equal to a\u0325\u0300 with decomposition",
myCollator.compare("\u00e0\u0325", "a\u0325\u0300") == 0);
}
+
+ public void testEqualsObject() throws ParseException {
+ String rule = "< a < b < c < d < e";
+ RuleBasedCollator coll = new RuleBasedCollator(rule);
+
+ assertEquals(Collator.TERTIARY, coll.getStrength());
+ // This is a harmony test, but it assumes that RuleBasedCollators default to
+ // NO_DECOMPOSITION, which isn't true on Android.
+ // assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
+ RuleBasedCollator other = new RuleBasedCollator(rule);
+ assertTrue(coll.equals(other));
+
+ coll.setStrength(Collator.PRIMARY);
+ assertFalse(coll.equals(other));
+
+ coll.setStrength(Collator.TERTIARY);
+ coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
+ other.setDecomposition(Collator.NO_DECOMPOSITION); // See comment above.
+ assertFalse(coll.equals(other));
+ }
+
+ public void test_Harmony_1352() throws Exception {
+ // Regression test for HARMONY-1352, that doesn't get run in the harmony test suite because
+ // of an earlier failure.
+ try {
+ new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator) null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ private void assertCollationElementIterator(CollationElementIterator it, Integer... offsets) {
+ for (int offset : offsets) {
+ assertEquals(offset, it.getOffset());
+ it.next();
+ }
+ assertEquals(CollationElementIterator.NULLORDER, it.next());
+ }
+
+ private void assertGetCollationElementIteratorString(Locale l, String s, Integer... offsets) {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(l);
+ assertCollationElementIterator(coll.getCollationElementIterator(s), offsets);
+ }
+
+ private void assertGetCollationElementIteratorCharacterIterator(Locale l, String s, Integer... offsets) {
+ RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(l);
+ CharacterIterator it = new StringCharacterIterator(s);
+ assertCollationElementIterator(coll.getCollationElementIterator(it), offsets);
+ }
+
+ public void testGetCollationElementIteratorString() throws Exception {
+ assertGetCollationElementIteratorString(new Locale("es", "", "TRADITIONAL"), "cha", 0, 2, 3);
+ assertGetCollationElementIteratorString(new Locale("es", "", ""), "cha", 0, 1, 2, 3);
+ assertGetCollationElementIteratorString(new Locale("de", "DE", ""), "\u00e6b", 0, 1, 1, 2);
+ }
+
+ public void testGetCollationElementIteratorCharacterIterator() throws Exception {
+ assertGetCollationElementIteratorCharacterIterator(new Locale("es", "", "TRADITIONAL"), "cha", 0, 2, 3);
+ assertGetCollationElementIteratorCharacterIterator(new Locale("es", "", ""), "cha", 0, 1, 2, 3);
+ assertGetCollationElementIteratorCharacterIterator(new Locale("de", "DE", ""), "\u00e6b", 0, 1, 1, 2);
+ }
}