Search in sources :

Example 11 with Collator

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

the class CollationAPITest method TestSetDecomposition.

/*
     * Tests the method public void setDecomposition(int decomposition)
     */
@Test
public void TestSetDecomposition() {
    // Tests when if ((decomposition != NO_DECOMPOSITION) && ...) is true
    int[] cases = { 0, 1, 14, 15, 18, 19 };
    for (int i = 0; i < cases.length; i++) {
        try {
            // Assuming -1 is not one of the values
            Collator c = Collator.getInstance();
            c.setDecomposition(cases[i]);
            errln("Collator.setDecomposition(int) is suppose to return " + "an exception for an invalid decomposition value of " + cases[i]);
        } catch (Exception e) {
        }
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 12 with Collator

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

the class CollationMiscTest method doTestOneReorderingAPITestCase.

/*
     * Utility function to test one collation reordering test case.
     * @param testcases Array of test cases.
     * @param n_testcases Size of the array testcases.
     * @param str_rules Array of rules.  These rules should be specifying the same rule in different formats.
     * @param n_rules Size of the array str_rules.
     */
private void doTestOneReorderingAPITestCase(OneTestCase[] testCases, int[] reorderTokens) {
    Collator myCollation = Collator.getInstance(ULocale.ENGLISH);
    myCollation.setReorderCodes(reorderTokens);
    for (OneTestCase testCase : testCases) {
        CollationTest.doTest(this, (RuleBasedCollator) myCollation, testCase.m_source_, testCase.m_target_, testCase.m_result_);
    }
}
Also used : Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator)

Example 13 with Collator

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

the class CollationMiscTest method TestFrozeness.

@Test
public void TestFrozeness() {
    Collator myCollation = Collator.getInstance(ULocale.CANADA);
    boolean exceptionCaught = false;
    myCollation.freeze();
    assertTrue("Collator not frozen.", myCollation.isFrozen());
    try {
        myCollation.setStrength(Collator.SECONDARY);
    } catch (UnsupportedOperationException e) {
        // expected
        exceptionCaught = true;
    }
    assertTrue("Frozen collator allowed change.", exceptionCaught);
    exceptionCaught = false;
    try {
        myCollation.setReorderCodes(ReorderCodes.DEFAULT);
    } catch (UnsupportedOperationException e) {
        // expected
        exceptionCaught = true;
    }
    assertTrue("Frozen collator allowed change.", exceptionCaught);
    exceptionCaught = false;
    try {
        myCollation.setVariableTop(12);
    } catch (UnsupportedOperationException e) {
        // expected
        exceptionCaught = true;
    }
    assertTrue("Frozen collator allowed change.", exceptionCaught);
    exceptionCaught = false;
    Collator myClone = null;
    try {
        myClone = (Collator) myCollation.clone();
    } catch (CloneNotSupportedException e) {
        // should not happen - clone is implemented in Collator
        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());
}
Also used : Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 14 with Collator

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

the class CollationMiscTest method TestInvalidListsAndRanges.

@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" };
    for (String rule : invalidRules) {
        try {
            Collator myCollation = new RuleBasedCollator(rule);
            warnln("ERROR: Creation of collator didn't fail for " + rule + " when it should.");
            CollationTest.doTest(this, (RuleBasedCollator) myCollation, "x", "y", -1);
        } catch (Exception e) {
            continue;
        }
        throw new IllegalArgumentException("ERROR: Invalid collator with rule " + rule + " worked fine.");
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 15 with Collator

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

the class CollationMiscTest method TestTibetanConformance.

@Test
public void TestTibetanConformance() {
    String[] test = { "\u0FB2\u0591\u0F71\u0061", "\u0FB2\u0F71\u0061" };
    try {
        Collator coll = Collator.getInstance();
        coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        if (coll.compare(test[0], test[1]) != 0) {
            errln("Tibetan comparison error");
        }
        CollationTest.doTest(this, (RuleBasedCollator) coll, test[0], test[1], 0);
    } catch (Exception e) {
        warnln("Error creating UCA collator");
    }
}
Also used : Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) 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