Search in sources :

Example 71 with Collator

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

the class CollationMiscTest method TestFunkyA.

@Test
public void TestFunkyA() {
    String[] testSourceCases = { "\u0041\u0300\u0301", "\u0041\u0300\u0316", "\u0041\u0300", "\u00C0\u0301", // this would work with forced normalization
    "\u00C0\u0316" };
    String[] testTargetCases = { "\u0041\u0301\u0300", "\u0041\u0316\u0300", "\u00C0", "\u0041\u0301\u0300", // this would work with forced normalization
    "\u0041\u0316\u0300" };
    int[] results = { 1, 0, 0, 1, 0 };
    Collator myCollation;
    try {
        myCollation = Collator.getInstance(new Locale("en", "US"));
    } catch (Exception e) {
        warnln("ERROR: in creation of rule based collator");
        return;
    }
    // logln("Testing some A letters, for some reason");
    myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    myCollation.setStrength(Collator.TERTIARY);
    for (int i = 0; i < 4; i++) {
        CollationTest.doTest(this, (RuleBasedCollator) myCollation, testSourceCases[i], testTargetCases[i], results[i]);
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 72 with Collator

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

the class CollationMiscTest method TestContractionEndCompare.

@Test
public void TestContractionEndCompare() {
    String rules = "&b=ch";
    String src = "bec";
    String tgt = "bech";
    Collator coll = null;
    try {
        coll = new RuleBasedCollator(rules);
    } catch (Exception e) {
        warnln("Collator creation failed " + rules);
        return;
    }
    CollationTest.doTest(this, (RuleBasedCollator) coll, src, tgt, 1);
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 73 with Collator

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

the class CollationMiscTest method TestBeforeRuleWithScriptReordering.

/*
     * This test ensures that characters placed before a character in a different script have the same lead byte
     * in their collation key before and after script reordering.
     */
@Test
public void TestBeforeRuleWithScriptReordering() throws Exception {
    /* build collator */
    String rules = "&[before 1]\u03b1 < \u0e01";
    int[] reorderCodes = { UScript.GREEK };
    int result;
    Collator myCollation = new RuleBasedCollator(rules);
    myCollation.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    myCollation.setStrength(Collator.TERTIARY);
    String base = "\u03b1";
    /* base */
    String before = "\u0e01";
    /* ko kai */
    /* check collation results - before rule applied but not script reordering */
    result = myCollation.compare(base, before);
    if (!(result > 0)) {
        errln("Collation result not correct before script reordering.");
    }
    /* check the lead byte of the collation keys before script reordering */
    CollationKey baseKey = myCollation.getCollationKey(base);
    CollationKey beforeKey = myCollation.getCollationKey(before);
    byte[] baseKeyBytes = baseKey.toByteArray();
    byte[] beforeKeyBytes = beforeKey.toByteArray();
    if (baseKeyBytes[0] != beforeKeyBytes[0]) {
        errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = " + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
    }
    /* reorder the scripts */
    myCollation.setReorderCodes(reorderCodes);
    /* check collation results - before rule applied and after script reordering */
    result = myCollation.compare(base, before);
    if (!(result > 0)) {
        errln("Collation result not correct after script reordering.");
    }
    /* check the lead byte of the collation keys after script reordering */
    baseKey = myCollation.getCollationKey(base);
    beforeKey = myCollation.getCollationKey(before);
    baseKeyBytes = baseKey.toByteArray();
    beforeKeyBytes = beforeKey.toByteArray();
    if (baseKeyBytes[0] != beforeKeyBytes[0]) {
        errln("Different lead byte for sort keys using before rule and before script reordering. base character lead byte = " + baseKeyBytes[0] + ", before character lead byte = " + beforeKeyBytes[0]);
    }
}
Also used : RuleBasedCollator(android.icu.text.RuleBasedCollator) 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 74 with Collator

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

the class CollationMiscTest method TestFCDProblem.

@Test
public void TestFCDProblem() {
    String s1 = "\u0430\u0306\u0325";
    String s2 = "\u04D1\u0325";
    Collator coll = null;
    try {
        coll = Collator.getInstance();
    } catch (Exception e) {
        warnln("Can't create collator");
        return;
    }
    coll.setDecomposition(Collator.NO_DECOMPOSITION);
    CollationTest.doTest(this, (RuleBasedCollator) coll, s1, s2, 0);
    coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    CollationTest.doTest(this, (RuleBasedCollator) coll, s1, s2, 0);
}
Also used : Collator(android.icu.text.Collator) RuleBasedCollator(android.icu.text.RuleBasedCollator) Test(org.junit.Test)

Example 75 with Collator

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

the class CollationRegressionTest method Test4124632.

// @bug 4124632
// 
// Collator::getCollationKey was hanging on certain character sequences
// 
@Test
public void Test4124632() /* char* par */
{
    Collator coll = null;
    try {
        coll = Collator.getInstance(Locale.JAPAN);
    } catch (Exception e) {
        errln("Failed to create collator for Locale::JAPAN");
        return;
    }
    String test = "\u0041\u0308\u0062\u0063";
    CollationKey key;
    try {
        key = coll.getCollationKey(test);
        logln(key.getSourceString());
    } catch (Exception e) {
        errln("CollationKey creation failed.");
    }
}
Also used : CollationKey(android.icu.text.CollationKey) 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