icu4c/source/samples/break/x64
icu4c/source/samples/break/x86
icu4c/source/samples/cal/*.d
+icu4c/source/samples/cal/*.o
icu4c/source/samples/cal/*.pdb
icu4c/source/samples/cal/*.vcxproj.user
icu4c/source/samples/cal/Debug
icu4c/source/samples/csdet/x64
icu4c/source/samples/csdet/x86
icu4c/source/samples/date/*.d
+icu4c/source/samples/date/*.o
icu4c/source/samples/date/*.pdb
icu4c/source/samples/date/*.vcxproj.user
icu4c/source/samples/date/Debug
icu4c/source/tools/ctestfw/x64
icu4c/source/tools/ctestfw/x86
icu4c/source/tools/escapesrc/*.d
+icu4c/source/tools/escapesrc/*.o
icu4c/source/tools/escapesrc/Makefile
icu4c/source/tools/escapesrc/output-*.cpp
icu4c/source/tools/genbrk/*.d
* Creates a ListFormatter appropriate for a locale and style.
*
* @param locale The locale.
- * @param style the style, either "standard", "duration", or "duration-short"
+ * @param style the style, either "standard", "or", "unit", "unit-narrow", or "unit-short"
* @param errorCode ICU error code, set if no data available for the given locale.
* @return A ListFormatter object created from internal data derived from
* CLDR data.
}
}
+void ListFormatterTest::DoTheRealListStyleTesting(Locale locale,
+ UnicodeString items[], int itemCount,
+ const char* style, const char* expected, IcuTestErrorCode status) {
+
+ LocalPointer<ListFormatter> formatter(
+ ListFormatter::createInstance(locale, style, status));
+
+ UnicodeString actualResult;
+ formatter->format(items, itemCount, actualResult, status);
+ assertEquals(style, UnicodeString(expected), actualResult);
+}
+
+void ListFormatterTest::TestDifferentStyles() {
+ Locale locale("fr");
+ UnicodeString input[4] = { u"rouge", u"jaune", u"bleu", u"vert" };
+ IcuTestErrorCode status(*this, "TestDifferentStyles()");
+
+ DoTheRealListStyleTesting(locale, input, 4, "standard", "rouge, jaune, bleu et vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, "or", "rouge, jaune, bleu ou vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, "unit", "rouge, jaune, bleu et vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, "unit-narrow", "rouge jaune bleu vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, "unit-short", "rouge, jaune, bleu et vert", status);
+}
+
+void ListFormatterTest::TestBadStylesFail() {
+ Locale locale("fr");
+ const char * badStyles[4] = { "", "duration", "duration-short", "something-clearly-wrong" };
+ IcuTestErrorCode status(*this, "TestBadStylesFail()");
+
+ for (int i = 0; i < 4; ++i) {
+ LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(locale, badStyles[i], status));
+ if (!status.expectErrorAndReset(U_MISSING_RESOURCE_ERROR, "style \"%s\"", badStyles[i])) {
+ // Do nothing, expectErrorAndReset already reports the error
+ }
+ }
+}
void ListFormatterTest::runIndexedTest(int32_t index, UBool exec,
const char* &name, char* /*par */) {
case 21: name = "TestFormattedValue";
if (exec) TestFormattedValue();
break;
+ case 22: name = "TestDifferentStyles";
+ if (exec) TestDifferentStyles();
+ break;
+ case 23: name = "TestBadStylesFail";
+ if (exec) TestBadStylesFail();
+ break;
default: name = ""; break;
}
}
void TestFieldPositionIteratorWith2ItemsPatternShift();
void TestFieldPositionIteratorWith3ItemsPatternShift();
void TestFormattedValue();
+ void TestDifferentStyles();
+ void TestBadStylesFail();
private:
void CheckFormatting(
UnicodeString four,
UnicodeString results[4],
const char* testName);
+ void DoTheRealListStyleTesting(
+ Locale locale,
+ UnicodeString items[],
+ int32_t itemCount,
+ const char* style,
+ const char* expected,
+ IcuTestErrorCode status);
private:
// Reused test data.
@Deprecated
public enum Style {
/**
- * Standard style.
+ * Standard, conjunction style.
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
STANDARD("standard"),
/**
- * Style for full durations
+ * Disjunction style.
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
- DURATION("unit"),
+ OR("or"),
/**
- * Style for durations in abbrevated form
+ * Style for full units
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
- DURATION_SHORT("unit-short"),
+ UNIT("unit"),
/**
- * Style for durations in narrow form
+ * Style for units in abbrevated form
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
- DURATION_NARROW("unit-narrow");
+ UNIT_SHORT("unit-short"),
+ /**
+ * Style for units in narrow form
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ @Deprecated
+ UNIT_NARROW("unit-narrow");
private final String name;
*
* @stable ICU 53
*/
- WIDE(ListFormatter.Style.DURATION, UnitWidth.FULL_NAME, UnitWidth.FULL_NAME),
+ WIDE(ListFormatter.Style.UNIT, UnitWidth.FULL_NAME, UnitWidth.FULL_NAME),
/**
* Abbreviate when possible.
*
* @stable ICU 53
*/
- SHORT(ListFormatter.Style.DURATION_SHORT, UnitWidth.SHORT, UnitWidth.ISO_CODE),
+ SHORT(ListFormatter.Style.UNIT_SHORT, UnitWidth.SHORT, UnitWidth.ISO_CODE),
/**
* Brief. Use only a symbol for the unit when possible.
*
* @stable ICU 53
*/
- NARROW(ListFormatter.Style.DURATION_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
+ NARROW(ListFormatter.Style.UNIT_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
/**
* Identical to NARROW except when formatMeasures is called with an hour and minute; minute and
*
* @stable ICU 53
*/
- NUMERIC(ListFormatter.Style.DURATION_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
+ NUMERIC(ListFormatter.Style.UNIT_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
/**
* The default format width for getCurrencyFormat(), which is to show the symbol for currency
* @deprecated ICU 61 This API is ICU internal only.
*/
@Deprecated
- DEFAULT_CURRENCY(ListFormatter.Style.DURATION, UnitWidth.FULL_NAME, UnitWidth.SHORT);
+ DEFAULT_CURRENCY(ListFormatter.Style.UNIT, UnitWidth.FULL_NAME, UnitWidth.SHORT);
private final ListFormatter.Style listFormatterStyle;
assertEquals("bug 9946", "{0}, {1}, and {2}", listFormatter.format("{0}", "{1}", "{2}"));
}
+
+ void DoTheRealListStyleTesting(ULocale locale, String items[], ListFormatter.Style style, String expected) {
+ ListFormatter listFormatter = ListFormatter.getInstance(locale, style);
+ assertEquals("Style \"" + style + "\"", expected, listFormatter.format(items));
+ }
+
+ @Test
+ public void TestDifferentStyles() {
+ ULocale locale = ULocale.FRENCH;
+ String[] input = { "rouge", "jaune", "bleu", "vert" };
+
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Style.STANDARD, "rouge, jaune, bleu et vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Style.OR, "rouge, jaune, bleu ou vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT, "rouge, jaune, bleu et vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT_NARROW, "rouge jaune bleu vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT_SHORT, "rouge, jaune, bleu et vert");
+ }
+
private boolean isDefaultLocaleEnglishLike() {
ULocale defaultLocale = ULocale.getDefault(ULocale.Category.FORMAT);
return defaultLocale.equals(ULocale.ENGLISH) || defaultLocale.equals(ULocale.US);