Search in sources :

Example 46 with UnicodeSet

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

the class StringTokenizerTest method TestMatchesAt.

/* Tests the method
     *      public int matchesAt(CharSequence text, int offset)
     */
@Test
public void TestMatchesAt() {
    // Empty set
    UnicodeSet us = new UnicodeSet();
    us.matchesAt((CharSequence) "dummy", 0);
    // Add an item
    us.add("dummy");
    us.matchesAt((CharSequence) "dummy", 0);
    // Add another item
    us.add("dummy2");
    // charAt(0) >
    us.matchesAt((CharSequence) "yummy", 0);
    // charAt(0) <
    us.matchesAt((CharSequence) "amy", 0);
    // Increase the set
    UnicodeSet us1 = new UnicodeSet(0, 100000);
    us1.matchesAt((CharSequence) "dummy", 0);
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 47 with UnicodeSet

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

the class StringTokenizerTest method TestAdd_int_int.

/* Tests the method
     *      private UnicodeSet add_unchecked(int start, int end)
     * from public UnicodeSet add(int start, int end)
     */
@Test
public void TestAdd_int_int() {
    UnicodeSet us = new UnicodeSet();
    int[] invalid = { UnicodeSet.MIN_VALUE - 1, UnicodeSet.MIN_VALUE - 2, UnicodeSet.MAX_VALUE + 1, UnicodeSet.MAX_VALUE + 2 };
    // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
    for (int i = 0; i < invalid.length; i++) {
        try {
            us.add(invalid[i], UnicodeSet.MAX_VALUE);
            errln("UnicodeSet.add(int start, int end) was suppose to give " + "an exception for an start invalid input of " + invalid[i]);
        } catch (Exception e) {
        }
    }
    // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
    for (int i = 0; i < invalid.length; i++) {
        try {
            us.add(UnicodeSet.MIN_VALUE, invalid[i]);
            errln("UnicodeSet.add(int start, int end) was suppose to give " + "an exception for an end invalid input of " + invalid[i]);
        } catch (Exception e) {
        }
    }
    // Tests when "else if (start == end)" is false
    if (!(us.add(UnicodeSet.MIN_VALUE + 1, UnicodeSet.MIN_VALUE).equals(us)))
        errln("UnicodeSet.add(int start, int end) was suppose to return " + "the same object because start of value " + (UnicodeSet.MIN_VALUE + 1) + " is greater than end of value " + UnicodeSet.MIN_VALUE);
    if (!(us.add(UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE - 1).equals(us)))
        errln("UnicodeSet.add(int start, int end) was suppose to return " + "the same object because start of value " + UnicodeSet.MAX_VALUE + " is greater than end of value " + (UnicodeSet.MAX_VALUE - 1));
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 48 with UnicodeSet

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

the class StringTokenizerTest method TestComplement_String.

/* Tests the method
         *      public final UnicodeSet complement(String s)
         */
@Test
public void TestComplement_String() {
    // Tests when "if (cp < 0)" is false
    UnicodeSet us = new UnicodeSet();
    us.add("dummy");
    try {
        us.complement("dummy");
    } catch (Exception e) {
        errln("UnicodeSet.complement(String s) was not suppose to give " + "an exception for 'dummy'.");
    }
    // Tests when "if (strings.contains(s))" is true
    us = new UnicodeSet();
    us.add("\uDC11");
    try {
        us.complement("\uDC11");
    } catch (Exception e) {
        errln("UnicodeSet.complement(String s) was not suppose to give " + "an exception for '\uDC11'.");
    }
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 49 with UnicodeSet

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

the class TrieMapTest method init.

@Before
public void init() throws Exception {
    if (unicodeTestMap.size() == 0) {
        if (TestFmwk.getExhaustiveness() < 5) {
            logln("\tShort version, timing for 1s:\t to get more accurate figures and test for reasonable times, use -e5 or more");
            t.setTimingPeriod(1 * Timer.SECONDS);
        } else {
            int seconds = TestFmwk.getExhaustiveness();
            logln("\tExhaustive version, timing for " + seconds + "s");
            t.setTimingPeriod(seconds * Timer.SECONDS);
            useSmallList = false;
        }
        int i = 0;
        UnicodeSet testSet = new UnicodeSet("[[:^C:]-[:sc=han:]]");
        for (String s : testSet) {
            int codePoint = s.codePointAt(0);
            String extendedName = UCharacter.getExtendedName(codePoint);
            if (!unicodeTestMap.containsKey(extendedName)) {
                unicodeTestMap.put(extendedName, i++);
            }
            if (i > 500 && useSmallList)
                break;
        }
        ULocale[] locales = useSmallList ? new ULocale[] { new ULocale("zh"), new ULocale("el") } : ULocale.getAvailableLocales();
        for (ULocale locale : locales) {
            if (locale.getDisplayCountry().length() != 0) {
                continue;
            }
            String localeName;
            for (String languageCode : ULocale.getISOLanguages()) {
                localeName = ULocale.getDisplayName(languageCode, locale);
                if (!localeName.equals(languageCode)) {
                    if (!unicodeTestMap.containsKey(localeName)) {
                        unicodeTestMap.put(localeName, MASK & i++);
                    }
                    if (SHORT)
                        break;
                }
            }
            for (String countryCode : ULocale.getISOCountries()) {
                localeName = ULocale.getDisplayCountry("und-" + countryCode, locale);
                if (!localeName.equals(countryCode)) {
                    if (!unicodeTestMap.containsKey(localeName)) {
                        unicodeTestMap.put(localeName, MASK & i++);
                    }
                    if (SHORT)
                        break;
                }
            }
        }
        int charCount = 0;
        for (String key : unicodeTestMap.keySet()) {
            charCount += key.length();
        }
        logln("\tTest Data Elements:\t\t\t" + nf.format(unicodeTestMap.size()));
        logln("\tTotal chars:\t\t\t" + nf.format(charCount));
    }
}
Also used : ULocale(android.icu.util.ULocale) UnicodeSet(android.icu.text.UnicodeSet) Before(org.junit.Before)

Example 50 with UnicodeSet

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

the class StringTokenizerTest method TestMatches.

/* Tests the method
     *      public int matches(Replaceable text, int[] offset, int limit, boolean incremental)
     */
@Test
public void TestMatches() {
    // Tests when "return incremental ? U_PARTIAL_MATCH : U_MATCH;" is true and false
    ReplaceableString rs = new ReplaceableString("dummy");
    // Create a large Unicode set
    UnicodeSet us = new UnicodeSet(0, 100000);
    us.add("dummy");
    int[] offset = { 0 };
    int limit = 0;
    if (us.matches(null, offset, limit, true) != UnicodeSet.U_PARTIAL_MATCH) {
        errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_PARTIAL_MATCH + " but got " + us.matches(null, offset, limit, true));
    }
    if (us.matches(null, offset, limit, false) != UnicodeSet.U_MATCH) {
        errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_MATCH + " but got " + us.matches(null, offset, limit, false));
    }
    // Tests when "int maxLen = forward ? limit-offset[0] : offset[0]-limit;" is true and false
    try {
        // Takes the letter "d"
        offset[0] = 0;
        us.matches(rs, offset, 1, true);
        // Takes the letter "y"
        offset[0] = 4;
        us.matches(rs, offset, 1, true);
    } catch (Exception e) {
        errln("UnicodeSet.matches is not suppose to return an exception");
    }
// TODO: Tests when "if (forward && length < highWaterLength)" is true
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) 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