Search in sources :

Example 1 with PluralRanges

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

the class PluralRangesTest method TestLocaleData.

@Test
public void TestLocaleData() {
    String[][] tests = { { "de", "other", "one", "one" }, { "xxx", "few", "few", "few" }, { "de", "one", "other", "other" }, { "de", "other", "one", "one" }, { "de", "other", "other", "other" }, { "ro", "one", "few", "few" }, { "ro", "one", "other", "other" }, { "ro", "few", "one", "few" } };
    for (String[] test : tests) {
        final ULocale locale = new ULocale(test[0]);
        final StandardPlural start = StandardPlural.fromString(test[1]);
        final StandardPlural end = StandardPlural.fromString(test[2]);
        final StandardPlural expected = StandardPlural.fromString(test[3]);
        final PluralRanges pluralRanges = Factory.getDefaultFactory().getPluralRanges(locale);
        StandardPlural actual = pluralRanges.get(start, end);
        assertEquals("Deriving range category", expected, actual);
    }
}
Also used : ULocale(android.icu.util.ULocale) StandardPlural(android.icu.impl.StandardPlural) PluralRanges(android.icu.text.PluralRanges) Test(org.junit.Test)

Example 2 with PluralRanges

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

the class PluralRulesLoader method getPluralRanges.

public PluralRanges getPluralRanges(ULocale locale) {
    // TODO markdavis Fix the bad fallback, here and elsewhere in this file.
    String localeId = ULocale.canonicalize(locale.getBaseName());
    PluralRanges result;
    while (null == (result = localeIdToPluralRanges.get(localeId))) {
        int ix = localeId.lastIndexOf("_");
        if (ix == -1) {
            result = UNKNOWN_RANGE;
            break;
        }
        localeId = localeId.substring(0, ix);
    }
    return result;
}
Also used : PluralRanges(android.icu.text.PluralRanges)

Example 3 with PluralRanges

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

the class PluralRangesTest method TestBasic.

@Test
public void TestBasic() {
    PluralRanges a = new PluralRanges();
    a.add(StandardPlural.ONE, StandardPlural.OTHER, StandardPlural.ONE);
    StandardPlural actual = a.get(StandardPlural.ONE, StandardPlural.OTHER);
    assertEquals("range", StandardPlural.ONE, actual);
    a.freeze();
    try {
        a.add(StandardPlural.ONE, StandardPlural.ONE, StandardPlural.ONE);
        errln("Failed to cause exception on frozen instance");
    } catch (UnsupportedOperationException e) {
    }
}
Also used : StandardPlural(android.icu.impl.StandardPlural) PluralRanges(android.icu.text.PluralRanges) Test(org.junit.Test)

Aggregations

PluralRanges (android.icu.text.PluralRanges)3 StandardPlural (android.icu.impl.StandardPlural)2 Test (org.junit.Test)2 ULocale (android.icu.util.ULocale)1