use of android.icu.text.MeasureFormat.FormatWidth 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 + "\"");
}
}
}
use of android.icu.text.MeasureFormat.FormatWidth in project j2objc by google.
the class PluralRangesTest method TestRangePattern.
@Test
public void TestRangePattern() {
String[][] tests = { { "de", "SHORT", "{0}–{1}" }, { "ja", "NARROW", "{0}~{1}" } };
for (String[] test : tests) {
ULocale ulocale = new ULocale(test[0]);
FormatWidth width = FormatWidth.valueOf(test[1]);
String expected = test[2];
String formatter = MeasureFormat.getRangeFormat(ulocale, width);
String actual = SimpleFormatterImpl.formatCompiledPattern(formatter, "{0}", "{1}");
assertEquals("range pattern " + Arrays.asList(test), expected, actual);
}
}
use of android.icu.text.MeasureFormat.FormatWidth in project j2objc by google.
the class PluralRangesTest method TestFormatting.
@Test
public void TestFormatting() {
Object[][] tests = { { 0.0, 1.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "0–1 degré Fahrenheit" }, { 1.0, 2.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "1–2 degrés Fahrenheit" }, { 3.1, 4.25, ULocale.FRANCE, FormatWidth.SHORT, MeasureUnit.FAHRENHEIT, "3,1–4,25 °F" }, { 3.1, 4.25, ULocale.ENGLISH, FormatWidth.SHORT, MeasureUnit.FAHRENHEIT, "3.1–4.25°F" }, { 3.1, 4.25, ULocale.CHINESE, FormatWidth.WIDE, MeasureUnit.INCH, "3.1-4.25英寸" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.WIDE, MeasureUnit.INCH, "0–1 inches" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.NARROW, Currency.getInstance("EUR"), "€0.00–1.00" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.NARROW, Currency.getInstance("EUR"), "0,00–1,00 €" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.NARROW, Currency.getInstance("JPY"), "0–100\u00a0JPY" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.SHORT, Currency.getInstance("EUR"), "EUR0.00–1.00" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.SHORT, Currency.getInstance("EUR"), "0,00–1,00\u00a0EUR" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.SHORT, Currency.getInstance("JPY"), "0–100\u00a0JPY" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0.00–1.00 euros" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0,00–1,00 euro" }, { 0.0, 2.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0,00–2,00 euros" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("JPY"), "0–100 yens japonais" } };
int i = 0;
for (Object[] test : tests) {
++i;
double low = (Double) test[0];
double high = (Double) test[1];
final ULocale locale = (ULocale) test[2];
final FormatWidth width = (FormatWidth) test[3];
final MeasureUnit unit = (MeasureUnit) test[4];
final Object expected = test[5];
MeasureFormat mf = MeasureFormat.getInstance(locale, width);
Object actual;
try {
actual = mf.formatMeasureRange(new Measure(low, unit), new Measure(high, unit));
} catch (Exception e) {
actual = e.getClass();
}
assertEquals(i + " Formatting unit", expected, actual);
}
}
use of android.icu.text.MeasureFormat.FormatWidth in project j2objc by google.
the class MeasureUnitTest method testSimplePer.
@Test
public void testSimplePer() {
Object DONT_CARE = null;
Object[][] data = new Object[][] { // per unit pattern
{ FormatWidth.WIDE, 1.0, MeasureUnit.SECOND, "1 pound per second", DONT_CARE, 0, 0 }, { FormatWidth.WIDE, 2.0, MeasureUnit.SECOND, "2 pounds per second", DONT_CARE, 0, 0 }, // compound pattern
{ FormatWidth.WIDE, 1.0, MeasureUnit.MINUTE, "1 pound per minute", DONT_CARE, 0, 0 }, { FormatWidth.WIDE, 2.0, MeasureUnit.MINUTE, "2 pounds per minute", DONT_CARE, 0, 0 }, // per unit
{ FormatWidth.SHORT, 1.0, MeasureUnit.SECOND, "1 lb/s", DONT_CARE, 0, 0 }, { FormatWidth.SHORT, 2.0, MeasureUnit.SECOND, "2 lb/s", DONT_CARE, 0, 0 }, // compound
{ FormatWidth.SHORT, 1.0, MeasureUnit.MINUTE, "1 lb/min", DONT_CARE, 0, 0 }, { FormatWidth.SHORT, 2.0, MeasureUnit.MINUTE, "2 lb/min", DONT_CARE, 0, 0 }, // per unit
{ FormatWidth.NARROW, 1.0, MeasureUnit.SECOND, "1#/s", DONT_CARE, 0, 0 }, { FormatWidth.NARROW, 2.0, MeasureUnit.SECOND, "2#/s", DONT_CARE, 0, 0 }, // compound
{ FormatWidth.NARROW, 1.0, MeasureUnit.MINUTE, "1#/min", DONT_CARE, 0, 0 }, { FormatWidth.NARROW, 2.0, MeasureUnit.MINUTE, "2#/min", DONT_CARE, 0, 0 }, // field positions
{ FormatWidth.SHORT, 23.3, MeasureUnit.SECOND, "23.3 lb/s", NumberFormat.Field.DECIMAL_SEPARATOR, 2, 3 }, { FormatWidth.SHORT, 23.3, MeasureUnit.SECOND, "23.3 lb/s", NumberFormat.Field.INTEGER, 0, 2 }, { FormatWidth.SHORT, 23.3, MeasureUnit.MINUTE, "23.3 lb/min", NumberFormat.Field.DECIMAL_SEPARATOR, 2, 3 }, { FormatWidth.SHORT, 23.3, MeasureUnit.MINUTE, "23.3 lb/min", NumberFormat.Field.INTEGER, 0, 2 } };
for (Object[] row : data) {
FormatWidth formatWidth = (FormatWidth) row[0];
Number amount = (Number) row[1];
MeasureUnit perUnit = (MeasureUnit) row[2];
String expected = row[3].toString();
NumberFormat.Field field = (NumberFormat.Field) row[4];
int startOffset = ((Integer) row[5]).intValue();
int endOffset = ((Integer) row[6]).intValue();
MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, formatWidth);
FieldPosition pos = field != null ? new FieldPosition(field) : new FieldPosition(0);
String prefix = "Prefix: ";
assertEquals("", prefix + expected, mf.formatMeasurePerUnit(new Measure(amount, MeasureUnit.POUND), perUnit, new StringBuilder(prefix), pos).toString());
if (field != DONT_CARE) {
assertEquals("startOffset", startOffset, pos.getBeginIndex() - prefix.length());
assertEquals("endOffset", endOffset, pos.getEndIndex() - prefix.length());
}
}
}
use of android.icu.text.MeasureFormat.FormatWidth in project j2objc by google.
the class MeasureUnitTest method TestGreek.
@Test
public void TestGreek() {
String[] locales = { "el_GR", "el" };
final MeasureUnit[] units = new MeasureUnit[] { MeasureUnit.SECOND, MeasureUnit.MINUTE, MeasureUnit.HOUR, MeasureUnit.DAY, MeasureUnit.WEEK, MeasureUnit.MONTH, MeasureUnit.YEAR };
FormatWidth[] styles = new FormatWidth[] { FormatWidth.WIDE, FormatWidth.SHORT };
int[] numbers = new int[] { 1, 7 };
String[] expected = { // "el_GR" 1 wide
"1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el_GR" 1 short
"1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
"1 έτ.", // "el_GR" 7 wide
"7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el_GR" 7 short
"7 δευτ.", "7 λεπ.", // hour (other)
"7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other)
"7 έτ.", // "el" 1 wide
"1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el" 1 short
"1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
"1 έτ.", // "el" 7 wide
"7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el" 7 short
"7 δευτ.", "7 λεπ.", // hour (other)
"7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other
"7 έτ." };
int counter = 0;
String formatted;
for (int locIndex = 0; locIndex < locales.length; ++locIndex) {
for (int numIndex = 0; numIndex < numbers.length; ++numIndex) {
for (int styleIndex = 0; styleIndex < styles.length; ++styleIndex) {
for (int unitIndex = 0; unitIndex < units.length; ++unitIndex) {
Measure m = new Measure(numbers[numIndex], units[unitIndex]);
MeasureFormat fmt = MeasureFormat.getInstance(new ULocale(locales[locIndex]), styles[styleIndex]);
formatted = fmt.format(m);
assertEquals("locale: " + locales[locIndex] + ", style: " + styles[styleIndex] + ", units: " + units[unitIndex] + ", value: " + numbers[numIndex], expected[counter], formatted);
++counter;
}
}
}
}
}
Aggregations