Search in sources :

Example 46 with RuleBasedCollator

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

the class CollationMiscTest method TestExpansion.

@Test
public void TestExpansion() {
    String[] testrules = { /*
             * This seems to have tested that M was not mapped to an expansion.
             * I believe the old builder just did that because it computed the extension CEs
             * at the very end, which was a bug.
             * Among other problems, it violated the core tailoring principle
             * by making an earlier rule depend on a later one.
             * And, of course, if M did not get an expansion, then it was primary different from K,
             * unlike what the rule &K<<M says.
            "&J << K / B & K << M",
             */
    "&J << K / B << M" };
    String[] testdata = { "JA", "MA", "KA", "KC", "JC", "MC" };
    Collator coll;
    for (int i = 0; i < testrules.length; i++) {
        // logln("Rule " + testrules[i] + " for testing\n");
        String rule = testrules[i];
        try {
            coll = new RuleBasedCollator(rule);
        } catch (Exception e) {
            warnln("Collator creation failed " + testrules[i]);
            return;
        }
        for (int j = 0; j < 5; j++) {
            CollationTest.doTest(this, (RuleBasedCollator) coll, testdata[j], testdata[j + 1], -1);
        }
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 47 with RuleBasedCollator

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

the class CollationMiscTest method TestJ3347.

@Test
public void TestJ3347() {
    try {
        Collator coll = Collator.getInstance(Locale.FRENCH);
        ((RuleBasedCollator) coll).setAlternateHandlingShifted(true);
        if (coll.compare("6", "!6") != 0) {
            errln("Jitterbug 3347 failed");
        }
    } catch (Exception e) {
        warnln("Error creating UCA collator");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 48 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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 49 with RuleBasedCollator

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

the class CollationMiscTest method TestShifted.

/**
 * Jitterbug 2726
 */
@Test
public void TestShifted() {
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance();
    collator.setStrength(Collator.PRIMARY);
    collator.setAlternateHandlingShifted(true);
    // works properly
    CollationTest.doTest(this, collator, " a", "a", 0);
    // inconsistent results
    CollationTest.doTest(this, collator, "a", "a ", 0);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 50 with RuleBasedCollator

use of android.icu.text.RuleBasedCollator 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)

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