Search in sources :

Example 11 with MeasureFormat

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

the class MeasureUnitTest method testFormatSingleArg.

@Test
public void testFormatSingleArg() {
    MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    assertEquals("", "5 meters", mf.format(new Measure(5, MeasureUnit.METER)));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 12 with MeasureFormat

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

the class MeasureUnitTest method testFormatMeasuresOneArg.

@Test
public void testFormatMeasuresOneArg() {
    MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    assertEquals("", "5 meters", mf.formatMeasures(new Measure(5, MeasureUnit.METER)));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 13 with MeasureFormat

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

the class MeasureUnitTest method testManyLocaleDurations.

@Test
public void testManyLocaleDurations() {
    Measure hours = new Measure(5, MeasureUnit.HOUR);
    Measure minutes = new Measure(37, MeasureUnit.MINUTE);
    ULocale ulocDanish = new ULocale("da");
    ULocale ulocSpanish = new ULocale("es");
    ULocale ulocFinnish = new ULocale("fi");
    ULocale ulocIcelandic = new ULocale("is");
    ULocale ulocNorwegianBok = new ULocale("nb");
    ULocale ulocNorwegianNyn = new ULocale("nn");
    ULocale ulocDutch = new ULocale("nl");
    ULocale ulocSwedish = new ULocale("sv");
    Object[][] data = new Object[][] { { ulocDanish, FormatWidth.NARROW, "5 t og 37 min" }, { ulocDanish, FormatWidth.NUMERIC, "5.37" }, { ULocale.GERMAN, FormatWidth.NARROW, "5 Std., 37 Min." }, { ULocale.GERMAN, FormatWidth.NUMERIC, "5:37" }, { ULocale.ENGLISH, FormatWidth.NARROW, "5h 37m" }, { ULocale.ENGLISH, FormatWidth.NUMERIC, "5:37" }, { ulocSpanish, FormatWidth.NARROW, "5h 37min" }, { ulocSpanish, FormatWidth.NUMERIC, "5:37" }, { ulocFinnish, FormatWidth.NARROW, "5t 37min" }, { ulocFinnish, FormatWidth.NUMERIC, "5.37" }, { ULocale.FRENCH, FormatWidth.NARROW, "5h 37m" }, { ULocale.FRENCH, FormatWidth.NUMERIC, "05:37" }, { ulocIcelandic, FormatWidth.NARROW, "5 klst. og 37 m\u00EDn." }, { ulocIcelandic, FormatWidth.NUMERIC, "5:37" }, { ULocale.JAPANESE, FormatWidth.NARROW, "5h37m" }, { ULocale.JAPANESE, FormatWidth.NUMERIC, "5:37" }, { ulocNorwegianBok, FormatWidth.NARROW, "5t, 37m" }, { ulocNorwegianBok, FormatWidth.NUMERIC, "5:37" }, { ulocDutch, FormatWidth.NARROW, "5 u, 37 m" }, { ulocDutch, FormatWidth.NUMERIC, "5:37" }, { ulocNorwegianNyn, FormatWidth.NARROW, "5 h og 37 min" }, { ulocNorwegianNyn, FormatWidth.NUMERIC, "5:37" }, { ulocSwedish, FormatWidth.NARROW, "5h 37m" }, { ulocSwedish, FormatWidth.NUMERIC, "5:37" }, { ULocale.CHINESE, FormatWidth.NARROW, "5\u5C0F\u65F637\u5206\u949F" }, { ULocale.CHINESE, FormatWidth.NUMERIC, "5:37" } };
    for (Object[] row : data) {
        MeasureFormat mf = null;
        try {
            mf = MeasureFormat.getInstance((ULocale) row[0], (FormatWidth) row[1]);
        } catch (Exception e) {
            errln("Exception creating MeasureFormat for locale " + row[0] + ", width " + row[1] + ": " + e);
            continue;
        }
        String result = mf.formatMeasures(hours, minutes);
        if (!result.equals(row[2])) {
            errln("MeasureFormat.formatMeasures for locale " + row[0] + ", width " + row[1] + ", expected \"" + (String) row[2] + "\", got \"" + result + "\"");
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) Measure(android.icu.util.Measure) FormatWidth(android.icu.text.MeasureFormat.FormatWidth) MeasureFormat(android.icu.text.MeasureFormat) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with MeasureFormat

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

the class MeasureUnitTest method testFormatMeasuresZeroArg.

@Test
public void testFormatMeasuresZeroArg() {
    MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
    assertEquals("", "", mf.formatMeasures());
}
Also used : MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 15 with MeasureFormat

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

the class MeasureUnitTest method testGetLocale.

@Test
public void testGetLocale() {
    MeasureFormat mf = MeasureFormat.getInstance(ULocale.GERMAN, FormatWidth.SHORT);
    assertEquals("", ULocale.GERMAN, mf.getLocale(ULocale.VALID_LOCALE));
}
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