Search in sources :

Example 26 with RuleBasedCollator

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

the class CollationMiscTest method TestUCARules.

@Test
public void TestUCARules() {
    try {
        // only root locale can have empty tailorings .. not English!
        RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(new Locale("", "", ""));
        String rule = coll.getRules(false);
        if (!rule.equals("")) {
            errln("Empty rule string should have empty rules " + rule);
        }
        rule = coll.getRules(true);
        if (rule.equals("")) {
            errln("UCA rule string should not be empty");
        }
        coll = new RuleBasedCollator(rule);
    } catch (Exception e) {
        // Android patch: Add --omitCollationRules to genrb.
        logln(e.getMessage());
    // Android patch end.
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 27 with RuleBasedCollator

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

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

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

Example 30 with RuleBasedCollator

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

the class CollationMiscTest method TestHangulTailoring.

@Test
public void TestHangulTailoring() {
    String[] koreanData = { "\uac00", "\u4f3d", "\u4f73", "\u5047", "\u50f9", "\u52a0", "\u53ef", "\u5475", "\u54e5", "\u5609", "\u5ac1", "\u5bb6", "\u6687", "\u67b6", "\u67b7", "\u67ef", "\u6b4c", "\u73c2", "\u75c2", "\u7a3c", "\u82db", "\u8304", "\u8857", "\u8888", "\u8a36", "\u8cc8", "\u8dcf", "\u8efb", "\u8fe6", "\u99d5", "\u4EEE", "\u50A2", "\u5496", "\u54FF", "\u5777", "\u5B8A", "\u659D", "\u698E", "\u6A9F", "\u73C8", "\u7B33", "\u801E", "\u8238", "\u846D", "\u8B0C" };
    String rules = "&\uac00 <<< \u4f3d <<< \u4f73 <<< \u5047 <<< \u50f9 <<< \u52a0 <<< \u53ef <<< \u5475 " + "<<< \u54e5 <<< \u5609 <<< \u5ac1 <<< \u5bb6 <<< \u6687 <<< \u67b6 <<< \u67b7 <<< \u67ef " + "<<< \u6b4c <<< \u73c2 <<< \u75c2 <<< \u7a3c <<< \u82db <<< \u8304 <<< \u8857 <<< \u8888 " + "<<< \u8a36 <<< \u8cc8 <<< \u8dcf <<< \u8efb <<< \u8fe6 <<< \u99d5 " + "<<< \u4EEE <<< \u50A2 <<< \u5496 <<< \u54FF <<< \u5777 <<< \u5B8A <<< \u659D <<< \u698E " + "<<< \u6A9F <<< \u73C8 <<< \u7B33 <<< \u801E <<< \u8238 <<< \u846D <<< \u8B0C";
    String rlz = rules;
    Collator coll = null;
    try {
        coll = new RuleBasedCollator(rlz);
    } catch (Exception e) {
        warnln("Unable to open collator with rules" + rules);
        return;
    }
    // logln("Using start of korean rules\n");
    genericOrderingTest(coll, koreanData);
// no such locale in icu4j
// logln("Using ko__LOTUS locale\n");
// genericLocaleStarter(new Locale("ko__LOTUS", ""), koreanData);
}
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