Search in sources :

Example 26 with Collator

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

the class CollationMiscTest method TestBocsuCoverage.

@Test
public void TestBocsuCoverage() {
    String test = "\u0041\u0441\u4441\\U00044441\u4441\u0441\u0041";
    Collator coll = Collator.getInstance();
    coll.setStrength(Collator.IDENTICAL);
    CollationKey key = coll.getCollationKey(test);
    logln("source:" + key.getSourceString());
}
Also used : CollationKey(android.icu.text.CollationKey) RawCollationKey(android.icu.text.RawCollationKey) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 27 with Collator

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

the class CollationMiscTest method doTestCollation.

/**
 * Convenient function to test collation rules.
 * @param testCases
 * @param rules Collation rules in ICU format.  All the strings in this
 *     array represent the same rule, expressed in different forms.
 */
private void doTestCollation(OneTestCase[] testCases, String[] rules) {
    Collator myCollation;
    for (String rule : rules) {
        try {
            myCollation = new RuleBasedCollator(rule);
        } catch (Exception e) {
            warnln("ERROR: in creation of rule based collator: " + e);
            return;
        }
        myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        myCollation.setStrength(Collator.TERTIARY);
        for (OneTestCase testCase : testCases) {
            CollationTest.doTest(this, (RuleBasedCollator) myCollation, testCase.m_source_, testCase.m_target_, testCase.m_result_);
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator)

Example 28 with Collator

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

the class CollationMiscTest method TestMaxVariable.

// ported from cmsccoll.c
@Test
public void TestMaxVariable() {
    int oldMax, max;
    String empty = "";
    String space = " ";
    String dot = ".";
    /* punctuation */
    String degree = "\u00b0";
    /* symbol */
    String dollar = "$";
    /* currency symbol */
    String zero = "0";
    /* digit */
    Collator coll = Collator.getInstance(ULocale.ROOT);
    oldMax = coll.getMaxVariable();
    logln(String.format("coll.getMaxVariable(root) -> %04x", oldMax));
    ((RuleBasedCollator) coll).setAlternateHandlingShifted(true);
    coll.setMaxVariable(Collator.ReorderCodes.SPACE);
    max = coll.getMaxVariable();
    logln(String.format("coll.setMaxVariable(space) -> %04x", max));
    if (max != Collator.ReorderCodes.SPACE || !coll.equals(empty, space) || coll.equals(empty, dot) || coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(space, dot) >= 0) {
        errln("coll.setMaxVariable(space) did not work");
    }
    coll.setMaxVariable(Collator.ReorderCodes.PUNCTUATION);
    max = coll.getMaxVariable();
    logln(String.format("coll.setMaxVariable(punctuation) -> %04x", max));
    if (max != Collator.ReorderCodes.PUNCTUATION || !coll.equals(empty, space) || !coll.equals(empty, dot) || coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(dot, degree) >= 0) {
        errln("coll.setMaxVariable(punctuation) did not work");
    }
    coll.setMaxVariable(Collator.ReorderCodes.SYMBOL);
    max = coll.getMaxVariable();
    logln(String.format("coll.setMaxVariable(symbol) -> %04x", max));
    if (max != Collator.ReorderCodes.SYMBOL || !coll.equals(empty, space) || !coll.equals(empty, dot) || !coll.equals(empty, degree) || coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(degree, dollar) >= 0) {
        errln("coll.setMaxVariable(symbol) did not work");
    }
    coll.setMaxVariable(Collator.ReorderCodes.CURRENCY);
    max = coll.getMaxVariable();
    logln(String.format("coll.setMaxVariable(currency) -> %04x", max));
    if (max != Collator.ReorderCodes.CURRENCY || !coll.equals(empty, space) || !coll.equals(empty, dot) || !coll.equals(empty, degree) || !coll.equals(empty, dollar) || coll.equals(empty, zero) || coll.compare(dollar, zero) >= 0) {
        errln("coll.setMaxVariable(currency) did not work");
    }
    logln("Test restoring maxVariable");
    coll.setMaxVariable(oldMax);
    if (oldMax != coll.getMaxVariable()) {
        errln("Couldn't restore old maxVariable");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 29 with Collator

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

the class CollationRegressionTest method Test4092260.

// @bug 4092260
// 
// Mu/micro conflict
// Micro symbol and greek lowercase letter Mu should sort identically
// 
@Test
public void Test4092260() /* char* par */
{
    Locale el = new Locale("el", "");
    Collator c = null;
    try {
        c = Collator.getInstance(el);
    } catch (Exception e) {
        errln("Failed to create collator for el locale.");
        return;
    }
    // These now have tertiary differences in UCA
    c.setStrength(Collator.SECONDARY);
    String[] tests = { "\u00B5", "\u003d", "\u03BC" };
    compareArray(c, tests);
}
Also used : Locale(java.util.Locale) ParseException(java.text.ParseException) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Example 30 with Collator

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

the class CollationRegressionTest method Test4141640.

// @bug 4141640
// 
// Support for Swedish gone in 1.1.6 (Can't create Swedish collator)
// 
@Test
public void Test4141640() /* char* par */
{
    // 
    // Rather than just creating a Swedish collator, we might as well
    // try to instantiate one for every locale available on the system
    // in order to prevent this sort of bug from cropping up in the future
    // 
    Locale[] locales = Collator.getAvailableLocales();
    for (int i = 0; i < locales.length; i += 1) {
        Collator c = null;
        try {
            c = Collator.getInstance(locales[i]);
            logln("source: " + c.getStrength());
        } catch (Exception e) {
            String msg = "";
            msg += "Could not create collator for locale ";
            msg += locales[i].getDisplayName();
            errln(msg);
        }
    }
}
Also used : Locale(java.util.Locale) ParseException(java.text.ParseException) RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) Test(org.junit.Test)

Aggregations

Collator (android.icu.text.Collator)81 Test (org.junit.Test)72 RuleBasedCollator (android.icu.text.RuleBasedCollator)70 Locale (java.util.Locale)25 ULocale (android.icu.util.ULocale)22 CollationKey (android.icu.text.CollationKey)15 MissingResourceException (java.util.MissingResourceException)11 RawCollationKey (android.icu.text.RawCollationKey)7 ParseException (java.text.ParseException)6 Random (java.util.Random)6 BreakIterator (android.icu.text.BreakIterator)5 StringCharacterIterator (java.text.StringCharacterIterator)5 LocaleDisplayNames (android.icu.text.LocaleDisplayNames)4 StringSearch (android.icu.text.StringSearch)4 CollationElementIterator (android.icu.text.CollationElementIterator)3 ArrayList (java.util.ArrayList)3 UnicodeSet (android.icu.text.UnicodeSet)2 GlobalizationPreferences (android.icu.util.GlobalizationPreferences)2 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2