Search in sources :

Example 6 with FormatWidth

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

the class MeasureUnitTest method testDisplayNames.

@Test
public void testDisplayNames() {
    Object[][] data = new Object[][] { // Unit, locale, width, expected result
    { MeasureUnit.YEAR, "en", FormatWidth.WIDE, "years" }, { MeasureUnit.YEAR, "ja", FormatWidth.WIDE, "年" }, { MeasureUnit.YEAR, "es", FormatWidth.WIDE, "años" }, { MeasureUnit.YEAR, "pt", FormatWidth.WIDE, "anos" }, { MeasureUnit.YEAR, "pt-PT", FormatWidth.WIDE, "anos" }, { MeasureUnit.AMPERE, "en", FormatWidth.WIDE, "amperes" }, { MeasureUnit.AMPERE, "ja", FormatWidth.WIDE, "アンペア" }, { MeasureUnit.AMPERE, "es", FormatWidth.WIDE, "amperios" }, { MeasureUnit.AMPERE, "pt", FormatWidth.WIDE, "amperes" }, { MeasureUnit.AMPERE, "pt-PT", FormatWidth.WIDE, "amperes" }, { MeasureUnit.METER_PER_SECOND_SQUARED, "pt", FormatWidth.WIDE, "metros por segundo ao quadrado" }, { MeasureUnit.METER_PER_SECOND_SQUARED, "pt-PT", FormatWidth.WIDE, "metros por segundo quadrado" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.NARROW, "km²" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.SHORT, "km²" }, { MeasureUnit.SQUARE_KILOMETER, "pt", FormatWidth.WIDE, "quilômetros quadrados" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.NARROW, "s" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.SHORT, "s" }, { MeasureUnit.SECOND, "pt-PT", FormatWidth.WIDE, "segundos" }, { MeasureUnit.SECOND, "pt", FormatWidth.NARROW, "seg" }, { MeasureUnit.SECOND, "pt", FormatWidth.SHORT, "segs" }, { MeasureUnit.SECOND, "pt", FormatWidth.WIDE, "segundos" } };
    for (Object[] test : data) {
        MeasureUnit unit = (MeasureUnit) test[0];
        ULocale locale = ULocale.forLanguageTag((String) test[1]);
        FormatWidth formatWidth = (FormatWidth) test[2];
        String expected = (String) test[3];
        MeasureFormat mf = MeasureFormat.getInstance(locale, formatWidth);
        String actual = mf.getUnitDisplayName(unit);
        assertEquals(String.format("Unit Display Name for %s, %s, %s", unit, locale, formatWidth), expected, actual);
    }
}
Also used : MeasureUnit(android.icu.util.MeasureUnit) ULocale(android.icu.util.ULocale) FormatWidth(android.icu.text.MeasureFormat.FormatWidth) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Aggregations

FormatWidth (android.icu.text.MeasureFormat.FormatWidth)6 Test (org.junit.Test)6 MeasureFormat (android.icu.text.MeasureFormat)5 ULocale (android.icu.util.ULocale)5 Measure (android.icu.util.Measure)4 MeasureUnit (android.icu.util.MeasureUnit)4 NumberFormat (android.icu.text.NumberFormat)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 FieldPosition (java.text.FieldPosition)1