Search in sources :

Example 36 with UnicodeSet

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

the class UnicodeSetTest method checkCodePoints.

private void checkCodePoints(String a, String b, CountMethod quantifier, SpanCondition spanCondition, String expectedReplaced, int expectedCount) {
    final String ab = a + b;
    UnicodeSetSpanner m = new UnicodeSetSpanner(new UnicodeSet("[{" + a + "}]"));
    assertEquals("new UnicodeSetSpanner(\"[{" + a + "}]\").countIn(\"" + ab + "\")", expectedCount, callCountIn(m, ab, quantifier, spanCondition));
    if (expectedReplaced == null) {
        expectedReplaced = "-" + b;
    }
    assertEquals("new UnicodeSetSpanner(\"[{" + a + "}]\").replaceFrom(\"" + ab + "\", \"-\")", expectedReplaced, m.replaceFrom(ab, "-", quantifier));
}
Also used : UnicodeSetSpanner(android.icu.text.UnicodeSetSpanner) UnicodeSet(android.icu.text.UnicodeSet)

Example 37 with UnicodeSet

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

the class TestUScript method TestScriptMetadata.

@Test
public void TestScriptMetadata() {
    UnicodeSet rtl = new UnicodeSet("[[:bc=R:][:bc=AL:]-[:Cn:]-[:sc=Common:]]");
    // So far, sample characters are uppercase.
    // Georgian is special.
    UnicodeSet cased = new UnicodeSet("[[:Lu:]-[:sc=Common:]-[:sc=Geor:]]");
    for (int sc = 0; sc < UScript.CODE_LIMIT; ++sc) {
        String sn = UScript.getShortName(sc);
        ScriptUsage usage = UScript.getUsage(sc);
        String sample = UScript.getSampleString(sc);
        UnicodeSet scriptSet = new UnicodeSet();
        scriptSet.applyIntPropertyValue(UProperty.SCRIPT, sc);
        if (usage == ScriptUsage.NOT_ENCODED) {
            // Java 6: sample.isEmpty()
            assertTrue(sn + " not encoded, no sample", sample.length() == 0);
            assertFalse(sn + " not encoded, not RTL", UScript.isRightToLeft(sc));
            assertFalse(sn + " not encoded, not LB letters", UScript.breaksBetweenLetters(sc));
            assertFalse(sn + " not encoded, not cased", UScript.isCased(sc));
            assertTrue(sn + " not encoded, no characters", scriptSet.isEmpty());
        } else {
            // Java 6: sample.isEmpty()
            assertFalse(sn + " encoded, has a sample character", sample.length() == 0);
            int firstChar = sample.codePointAt(0);
            int charScript = getCharScript(sc);
            assertEquals(sn + " script(sample(script))", charScript, UScript.getScript(firstChar));
            assertEquals(sn + " RTL vs. set", rtl.contains(firstChar), UScript.isRightToLeft(sc));
            assertEquals(sn + " cased vs. set", cased.contains(firstChar), UScript.isCased(sc));
            assertEquals(sn + " encoded, has characters", sc == charScript, !scriptSet.isEmpty());
            if (UScript.isRightToLeft(sc)) {
                rtl.removeAll(scriptSet);
            }
            if (UScript.isCased(sc)) {
                cased.removeAll(scriptSet);
            }
        }
    }
    assertEquals("no remaining RTL characters", "[]", rtl.toPattern(true));
    assertEquals("no remaining cased characters", "[]", cased.toPattern(true));
    assertTrue("Hani breaks between letters", UScript.breaksBetweenLetters(UScript.HAN));
    assertTrue("Thai breaks between letters", UScript.breaksBetweenLetters(UScript.THAI));
    assertFalse("Latn does not break between letters", UScript.breaksBetweenLetters(UScript.LATIN));
}
Also used : ScriptUsage(android.icu.lang.UScript.ScriptUsage) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 38 with UnicodeSet

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

the class UnicodeSetTest method expectEqual.

void expectEqual(String name, String pat1, String pat2) {
    UnicodeSet set1, set2;
    try {
        set1 = new UnicodeSet(pat1);
        set2 = new UnicodeSet(pat2);
    } catch (IllegalArgumentException e) {
        errln("FAIL: Couldn't create UnicodeSet from pattern for \"" + name + "\": " + e.getMessage());
        return;
    }
    if (!set1.equals(set2)) {
        errln("FAIL: Sets built from patterns differ for \"" + name + "\"");
    }
}
Also used : UnicodeSet(android.icu.text.UnicodeSet)

Example 39 with UnicodeSet

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

the class UnicodeSetTest method TestClone.

/**
 * Test cloning of UnicodeSet
 */
@Test
public void TestClone() {
    UnicodeSet s = new UnicodeSet("[abcxyz]");
    UnicodeSet t = (UnicodeSet) s.clone();
    expectContainment(t, "abc", "def");
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 40 with UnicodeSet

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

the class UnicodeSetTest method TestCloseOver.

/**
 * Test closure API.
 */
@Test
public void TestCloseOver() {
    String CASE = String.valueOf(UnicodeSet.CASE);
    String[] DATA = { // selector, input, output
    CASE, "[aq\u00DF{Bc}{bC}{Fi}]", // U+1E9E LATIN CAPITAL LETTER SHARP S is new in Unicode 5.1
    "[aAqQ\u00DF\u1E9E\uFB01{ss}{bc}{fi}]", CASE, // 'DZ'
    "[\u01F1]", "[\u01F1\u01F2\u01F3]", CASE, "[\u1FB4]", "[\u1FB4{\u03AC\u03B9}]", CASE, "[{F\uFB01}]", "[\uFB03{ffi}]", CASE, "[a-z]", "[A-Za-z\u017F\u212A]", CASE, "[abc]", "[A-Ca-c]", CASE, "[ABC]", "[A-Ca-c]" };
    UnicodeSet s = new UnicodeSet();
    UnicodeSet t = new UnicodeSet();
    for (int i = 0; i < DATA.length; i += 3) {
        int selector = Integer.parseInt(DATA[i]);
        String pat = DATA[i + 1];
        String exp = DATA[i + 2];
        s.applyPattern(pat);
        s.closeOver(selector);
        t.applyPattern(exp);
        if (s.equals(t)) {
            logln("Ok: " + pat + ".closeOver(" + selector + ") => " + exp);
        } else {
            errln("FAIL: " + pat + ".closeOver(" + selector + ") => " + s.toPattern(true) + ", expected " + exp);
        }
    }
    // Test the pattern API
    s.applyPattern("[abc]", UnicodeSet.CASE);
    expectContainment(s, "abcABC", "defDEF");
    s = new UnicodeSet("[^abc]", UnicodeSet.CASE);
    expectContainment(s, "defDEF", "abcABC");
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

UnicodeSet (android.icu.text.UnicodeSet)158 Test (org.junit.Test)112 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)25 Transliterator (android.icu.text.Transliterator)19 ReplaceableString (android.icu.text.ReplaceableString)14 ULocale (android.icu.util.ULocale)13 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)9 Normalizer2 (android.icu.text.Normalizer2)7 RuleBasedCollator (android.icu.text.RuleBasedCollator)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 FilteredNormalizer2 (android.icu.text.FilteredNormalizer2)4 SpoofChecker (android.icu.text.SpoofChecker)4 TreeSet (java.util.TreeSet)4 UnicodeMap (android.icu.dev.util.UnicodeMap)3 AlphabeticIndex (android.icu.text.AlphabeticIndex)3 CollationKey (android.icu.text.CollationKey)3 RawCollationKey (android.icu.text.RawCollationKey)3 CheckResult (android.icu.text.SpoofChecker.CheckResult)3 SpanCondition (android.icu.text.UnicodeSet.SpanCondition)3