Search in sources :

Example 51 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator in project j2objc by google.

the class CollationRegressionTest method Test4244884.

@Test
public void Test4244884() throws Exception {
    RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
    coll = new RuleBasedCollator(coll.getRules() + " & C < ch , cH , Ch , CH < cat < crunchy");
    String[] testStrings = new String[] { "car", "cave", "clamp", "cramp", "czar", "church", "catalogue", "crunchy", "dog" };
    for (int i = 1; i < testStrings.length; i++) {
        if (coll.compare(testStrings[i - 1], testStrings[i]) >= 0) {
            errln("error: \"" + testStrings[i - 1] + "\" is greater than or equal to \"" + testStrings[i] + "\".");
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 52 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator in project j2objc by google.

the class CollationRegressionTest method Test4663220.

// CollationElementIterator set doesn't work propertly with next/prev
@Test
public void Test4663220() {
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(Locale.US);
    java.text.StringCharacterIterator stringIter = new java.text.StringCharacterIterator("fox");
    CollationElementIterator iter = collator.getCollationElementIterator(stringIter);
    int[] elements_next = new int[3];
    logln("calling next:");
    for (int i = 0; i < 3; ++i) {
        logln("[" + i + "] " + (elements_next[i] = iter.next()));
    }
    int[] elements_fwd = new int[3];
    logln("calling set/next:");
    for (int i = 0; i < 3; ++i) {
        iter.setOffset(i);
        logln("[" + i + "] " + (elements_fwd[i] = iter.next()));
    }
    for (int i = 0; i < 3; ++i) {
        if (elements_next[i] != elements_fwd[i]) {
            errln("mismatch at position " + i + ": " + elements_next[i] + " != " + elements_fwd[i]);
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) CollationElementIterator(android.icu.text.CollationElementIterator) Test(org.junit.Test)

Example 53 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator in project j2objc by google.

the class CollationRegressionTest method Test4087243.

// @bug 4087243
// 
// CollationKey takes ignorable strings into account when it shouldn't
// 
@Test
public void Test4087243() /* char* par */
{
    RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
    c.setStrength(Collator.TERTIARY);
    String[] tests = { // 1 2 3  =  1 2 3 ctrl-A
    "\u0031\u0032\u0033", // 1 2 3  =  1 2 3 ctrl-A
    "\u003d", // 1 2 3  =  1 2 3 ctrl-A
    "\u0031\u0032\u0033\u0001" };
    compareArray(c, tests);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 54 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator in project j2objc by google.

the class CollationRegressionTest method Test4062418.

// @bug 4062418
// 
// Secondary/Tertiary comparison incorrect in French Secondary
// 
@Test
public void Test4062418() /* char* par */
{
    RuleBasedCollator c = null;
    try {
        c = (RuleBasedCollator) Collator.getInstance(Locale.CANADA_FRENCH);
    } catch (Exception e) {
        errln("Failed to create collator for Locale.CANADA_FRENCH");
        return;
    }
    c.setStrength(Collator.SECONDARY);
    String[] tests = { // Comparing accents from end, p\u00e9ch\u00e9 is greater
    "p\u00eache", // Comparing accents from end, p\u00e9ch\u00e9 is greater
    "<", // Comparing accents from end, p\u00e9ch\u00e9 is greater
    "p\u00e9ch\u00e9" };
    compareArray(c, tests);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 55 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator in project j2objc by google.

the class CollationRegressionTest method Test4076676.

// @bug 4076676
// 
// Bad canonicalization of same-class combining characters
// 
@Test
public void Test4076676() /* char* par */
{
    // These combining characters are all in the same class, so they should not
    // be reordered, and they should compare as unequal.
    final String s1 = "\u0041\u0301\u0302\u0300";
    final String s2 = "\u0041\u0302\u0300\u0301";
    RuleBasedCollator c = (RuleBasedCollator) Collator.getInstance(Locale.US);
    c.setStrength(Collator.TERTIARY);
    if (c.compare(s1, s2) == 0) {
        errln("Same-class combining chars were reordered");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Aggregations

RuleBasedCollator (android.icu.text.RuleBasedCollator)140 Test (org.junit.Test)124 Collator (android.icu.text.Collator)42 ULocale (android.icu.util.ULocale)26 CollationElementIterator (android.icu.text.CollationElementIterator)25 Locale (java.util.Locale)22 CollationKey (android.icu.text.CollationKey)17 StringCharacterIterator (java.text.StringCharacterIterator)16 StringSearch (android.icu.text.StringSearch)14 RawCollationKey (android.icu.text.RawCollationKey)11 ParseException (java.text.ParseException)10 UnicodeSet (android.icu.text.UnicodeSet)8 AlphabeticIndex (android.icu.text.AlphabeticIndex)6 BreakIterator (android.icu.text.BreakIterator)6 MissingResourceException (java.util.MissingResourceException)5 IOException (java.io.IOException)4 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)3 UCharacterIterator (android.icu.text.UCharacterIterator)2 CharacterIterator (java.text.CharacterIterator)2 ArrayList (java.util.ArrayList)2