Search in sources :

Example 31 with MeasureFormat

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

the class MeasureUnitTest method testOldFormatWithList.

@Test
public void testOldFormatWithList() {
    List<Measure> measures = new ArrayList<Measure>(2);
    measures.add(new Measure(5, MeasureUnit.ACRE));
    measures.add(new Measure(3000, MeasureUnit.SQUARE_FOOT));
    MeasureFormat fmt = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    assertEquals("", "5 acres, 3,000 square feet", fmt.format(measures));
    assertEquals("", "5 acres", fmt.format(measures.subList(0, 1)));
    List<String> badList = new ArrayList<String>();
    badList.add("be");
    badList.add("you");
    try {
        fmt.format(badList);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException expected) {
    // Expected
    }
}
Also used : Measure(android.icu.util.Measure) ArrayList(java.util.ArrayList) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 32 with MeasureFormat

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

the class MeasureUnitTest method testCurrencyFormatLocale.

@Test
public void testCurrencyFormatLocale() {
    MeasureFormat mfu = MeasureFormat.getCurrencyFormat(ULocale.FRANCE);
    MeasureFormat mfj = MeasureFormat.getCurrencyFormat(Locale.FRANCE);
    assertEquals("getCurrencyFormat ULocale/Locale", mfu, mfj);
}
Also used : MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 33 with MeasureFormat

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

the class MeasureUnitTest method testOldFormatWithArray.

@Test
public void testOldFormatWithArray() {
    Measure[] measures = new Measure[] { new Measure(5, MeasureUnit.ACRE), new Measure(3000, MeasureUnit.SQUARE_FOOT) };
    MeasureFormat fmt = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    assertEquals("", "5 acres, 3,000 square feet", fmt.format(measures));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 34 with MeasureFormat

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

the class MeasureUnitTest method testNumeratorPlurals.

@Test
public void testNumeratorPlurals() {
    ULocale polish = new ULocale("pl");
    Object[][] data = new Object[][] { { 1, "1 stopa na sekundę" }, { 2, "2 stopy na sekundę" }, { 5, "5 stóp na sekundę" }, { 1.5, "1,5 stopy na sekundę" } };
    for (Object[] row : data) {
        MeasureFormat mf = MeasureFormat.getInstance(polish, FormatWidth.WIDE);
        assertEquals("", row[1], mf.formatMeasurePerUnit(new Measure((Number) row[0], MeasureUnit.FOOT), MeasureUnit.SECOND, new StringBuilder(), new FieldPosition(0)).toString());
    }
}
Also used : ULocale(android.icu.util.ULocale) Measure(android.icu.util.Measure) FieldPosition(java.text.FieldPosition) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 35 with MeasureFormat

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

the class MeasureUnitTest method testOldFormatBadArg.

@Test
public void testOldFormatBadArg() {
    MeasureFormat fmt = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    try {
        fmt.format("be");
        fail("Expected IllegalArgumentExceptino.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
}
Also used : MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Aggregations

MeasureFormat (android.icu.text.MeasureFormat)38 Test (org.junit.Test)32 Measure (android.icu.util.Measure)26 ULocale (android.icu.util.ULocale)11 Locale (java.util.Locale)8 ArrayList (java.util.ArrayList)7 SpannableStringBuilder (android.text.SpannableStringBuilder)6 TtsSpan (android.text.style.TtsSpan)6 FormatWidth (android.icu.text.MeasureFormat.FormatWidth)5 NumberFormat (android.icu.text.NumberFormat)5 FieldPosition (java.text.FieldPosition)5 MeasureUnit (android.icu.util.MeasureUnit)4 CurrencyAmount (android.icu.util.CurrencyAmount)3 ParseException (java.text.ParseException)3 BigDecimal (android.icu.math.BigDecimal)2 IOException (java.io.IOException)2 ResourceReader (android.icu.impl.data.ResourceReader)1 TokenIterator (android.icu.impl.data.TokenIterator)1 CompactDecimalFormat (android.icu.text.CompactDecimalFormat)1 DecimalFormat (android.icu.text.DecimalFormat)1