use of android.icu.text.PluralFormat in project j2objc by google.
the class PluralFormatUnitTest method TestOrdinalFormat.
@Test
public void TestOrdinalFormat() {
String pattern = "one{#st file}two{#nd file}few{#rd file}other{#th file}";
PluralFormat pf = new PluralFormat(ULocale.ENGLISH, PluralType.ORDINAL, pattern);
assertEquals("PluralFormat.format(321)", "321st file", pf.format(321));
assertEquals("PluralFormat.format(22)", "22nd file", pf.format(22));
assertEquals("PluralFormat.format(3)", "3rd file", pf.format(3));
// Code coverage: Use the other new-for-PluralType constructor as well.
pf = new PluralFormat(ULocale.ENGLISH, PluralType.ORDINAL);
pf.applyPattern(pattern);
assertEquals("PluralFormat.format(456)", "456th file", pf.format(456));
assertEquals("PluralFormat.format(111)", "111th file", pf.format(111));
// Code coverage: Use Locale not ULocale.
pf = new PluralFormat(Locale.ENGLISH, PluralType.ORDINAL);
pf.applyPattern(pattern);
assertEquals("PluralFormat.format(456)", "456th file", pf.format(456));
assertEquals("PluralFormat.format(111)", "111th file", pf.format(111));
}
use of android.icu.text.PluralFormat in project j2objc by google.
the class PluralFormatTest method helperTestRules.
private void helperTestRules(String localeIDs, String testPattern, Map<Integer, String> changes) {
String[] locales = Utility.split(localeIDs, ',');
// Create example outputs for all supported locales.
/*
System.out.println("\n" + localeIDs);
String lastValue = (String) changes.get(new Integer(0));
int lastNumber = 0;
for (int i = 1; i < 199; ++i) {
if (changes.get(new Integer(i)) != null) {
if (lastNumber == i-1) {
System.out.println(lastNumber + ": " + lastValue);
} else {
System.out.println(lastNumber + "... " + (i-1) + ": " + lastValue);
}
lastNumber = i;
lastValue = (String) changes.get(new Integer(i));
}
}
System.out.println(lastNumber + "..." + 199 + ": " + lastValue);
*/
log("test pattern: '" + testPattern + "'");
for (int i = 0; i < locales.length; ++i) {
try {
PluralFormat plf = new PluralFormat(new ULocale(locales[i]), testPattern);
log("plf: " + plf);
String expected = (String) changes.get(new Integer(0));
for (int n = 0; n < 200; ++n) {
String value = changes.get(n);
if (value != null) {
expected = value;
}
assertEquals("Locale: " + locales[i] + ", number: " + n, expected, plf.format(n));
}
} catch (IllegalArgumentException e) {
errln(e.getMessage() + " locale: " + locales[i] + " pattern: '" + testPattern + "' " + System.currentTimeMillis());
}
}
}
use of android.icu.text.PluralFormat in project j2objc by google.
the class PluralFormatUnitTest method TestEquals.
public void TestEquals() {
// There is neither clone() nor a copy constructor.
PluralFormat de_fee_1 = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fee}");
PluralFormat de_fee_2 = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fee}");
PluralFormat de_fi = new PluralFormat(ULocale.GERMAN, PluralType.CARDINAL, "other{fi}");
PluralFormat fr_fee = new PluralFormat(ULocale.FRENCH, PluralType.CARDINAL, "other{fee}");
assertTrue("different de_fee objects", de_fee_1 != de_fee_2);
assertTrue("equal de_fee objects", de_fee_1.equals(de_fee_2));
assertFalse("different pattern strings", de_fee_1.equals(de_fi));
assertFalse("different locales", de_fee_1.equals(fr_fee));
}
use of android.icu.text.PluralFormat in project j2objc by google.
the class PluralFormatUnitTest method TestNegative.
@Test
public void TestNegative() {
PluralFormat pluralFormat = new PluralFormat(ULocale.ENGLISH, "one{# foot}other{# feet}");
String actual = pluralFormat.format(-3);
assertEquals(pluralFormat.toString(), "-3 feet", actual);
}
use of android.icu.text.PluralFormat in project j2objc by google.
the class PluralFormatUnitTest method TestSetLocale.
@Test
public void TestSetLocale() {
// Create rules for testing.
PluralRules oddAndEven = PluralRules.createRules("odd__: n mod 2 is 1");
PluralFormat plFmt = new PluralFormat(oddAndEven);
plFmt.applyPattern("odd__{odd} other{even}");
plFmt.setLocale(ULocale.ENGLISH);
// Check that pattern gets deleted.
NumberFormat nrFmt = NumberFormat.getInstance(ULocale.ENGLISH);
assertEquals("pattern was not resetted by setLocale() call.", nrFmt.format(5), plFmt.format(5));
// Check that rules got updated.
plFmt.applyPattern("odd__{odd} other{even}");
assertEquals("SetLocale should reset rules but did not.", "even", plFmt.format(1));
plFmt.applyPattern("one{one} other{not one}");
for (int i = 0; i < 20; ++i) {
assertEquals("Wrong ruleset loaded by setLocale()", ((i == 1) ? "one" : "not one"), plFmt.format(i));
}
}
Aggregations