mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-16 10:17:23 +00:00
ICU-22668 Added unit tests to verify that CLDR-17892 addresses the original problem reported here and took out an
earlier hack in the Java code to work around the original problem.
This commit is contained in:
parent
1c2a1c50b7
commit
9adcf8bd09
5 changed files with 85 additions and 6 deletions
icu4c/source/test/cintltst
icu4j/main/core/src
main/java/com/ibm/icu/text
test/java/com/ibm/icu/dev/test/format
|
@ -343,6 +343,8 @@ static const RelDateTimeFormatTestItem fmtTestItems[] = {
|
|||
ak_decDef_long_stdAlon_sec, ak_attrDef_long_stdAlon_sec},
|
||||
{ "en_IN", -1, UDAT_STYLE_SHORT, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_WEDNESDAY,
|
||||
enIN_decDef_short_midSent_weds, enIN_attrDef_short_midSent_weds},
|
||||
{ "en@calendar=iso8601", -1, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_SECOND,
|
||||
en_decDef_long_midSent_sec, en_attrDef_long_midSent_sec },
|
||||
{ NULL, 0, (UDateRelativeDateTimeFormatterStyle)0, (UDisplayContext)0, (URelativeDateTimeUnit)0, NULL, NULL } /* terminator */
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h> // for sprintf()
|
||||
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/udatpg.h"
|
||||
|
@ -51,7 +52,9 @@ static void TestGetDefaultHourCycleOnEmptyInstance(void);
|
|||
static void TestEras(void);
|
||||
static void TestDateTimePatterns(void);
|
||||
static void TestRegionOverride(void);
|
||||
static void TestISO8601(void);
|
||||
|
||||
|
||||
void addDateTimePatternGeneratorTest(TestNode** root) {
|
||||
TESTCASE(TestOpenClose);
|
||||
TESTCASE(TestUsage);
|
||||
|
@ -63,6 +66,7 @@ void addDateTimePatternGeneratorTest(TestNode** root) {
|
|||
TESTCASE(TestEras);
|
||||
TESTCASE(TestDateTimePatterns);
|
||||
TESTCASE(TestRegionOverride);
|
||||
TESTCASE(TestISO8601);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -836,4 +840,46 @@ static void TestRegionOverride(void) {
|
|||
udatpg_close(dtpg);
|
||||
}
|
||||
}
|
||||
|
||||
static void TestISO8601(void) {
|
||||
typedef struct TestCase {
|
||||
const char* locale;
|
||||
const UChar* skeleton;
|
||||
const UChar* expectedPattern;
|
||||
} TestCase;
|
||||
|
||||
const TestCase testCases[] = {
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", u"Edjmm", u"d, EEE, h:mm a" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EdHmm", u"d, EEE, HH:mm" },
|
||||
|
||||
{ "en_US@calendar=iso8601", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" },
|
||||
{ "en_US@calendar=iso8601", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" },
|
||||
{ "en_US@calendar=iso8601", u"Edjmm", u"d, EEE, h:mm a" },
|
||||
{ "en_US@calendar=iso8601", u"EdHmm", u"d, EEE, HH:mm" },
|
||||
|
||||
{ "en_US", u"EEEEyMMMMdjmm", u"EEEE, MMMM d, y 'at' h:mm a" },
|
||||
{ "en_US", u"EEEEyMMMMdHmm", u"EEEE, MMMM d, y 'at' HH:mm" },
|
||||
{ "en_US", u"Edjmm", u"d EEE, h:mm a" },
|
||||
{ "en_US", u"EdHmm", u"d EEE, HH:mm" },
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < UPRV_LENGTHOF(testCases); i++) {
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
UDateTimePatternGenerator* dtpg = udatpg_open(testCases[i].locale, &err);
|
||||
|
||||
if (assertSuccess("Error creating dtpg", &err)) {
|
||||
UChar actualPattern[200];
|
||||
|
||||
udatpg_getBestPatternWithOptions(dtpg, testCases[i].skeleton, -1, 0, actualPattern, UPRV_LENGTHOF(actualPattern), &err);
|
||||
if (assertSuccess("Error getting best pattern", &err)) {
|
||||
char errorMessage[200];
|
||||
snprintf(errorMessage, UPRV_LENGTHOF(errorMessage), "Wrong pattern for %s and %s", testCases[i].locale, austrdup(testCases[i].skeleton));
|
||||
assertUEquals(errorMessage, testCases[i].expectedPattern, actualPattern);
|
||||
}
|
||||
}
|
||||
udatpg_close(dtpg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -175,12 +175,6 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
|
|||
// first load with the ICU patterns
|
||||
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, uLocale);
|
||||
String calendarTypeToUse = getCalendarTypeToUse(uLocale);
|
||||
// TODO: this is a HACK to work around ICU-22668/CLDR-17892! Remove once they're fixed!
|
||||
// (Without this hack, DateTimeGeneratorTest.testISO8601() fails. The corresponding test
|
||||
// on the C++ side still _passes_, so I have NOT added this hack on the C++ side. --rtg 8/21/24)
|
||||
if (calendarTypeToUse.equals("iso8601")) {
|
||||
calendarTypeToUse = "gregorian";
|
||||
}
|
||||
// TODO: See ICU-22867
|
||||
ICUResourceBundle dateTimePatterns = rb.getWithFallback("calendar/" + calendarTypeToUse + "/DateTimePatterns");
|
||||
if (dateTimePatterns.getType() != UResourceBundle.ARRAY || dateTimePatterns.getSize() < 8) {
|
||||
|
|
|
@ -2066,4 +2066,38 @@ public class DateTimeGeneratorTest extends CoreTestFmwk {
|
|||
assertEquals("Wrong pattern", expectedPattern, actualPattern);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testISO8601More() {
|
||||
final String[][] testCases = {
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", "Edjmm", "d, EEE, h:mm a" },
|
||||
{ "en_GB@calendar=iso8601;rg=uszzzz", "EdHmm", "d, EEE, HH:mm" },
|
||||
|
||||
{ "en_US@calendar=iso8601", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" },
|
||||
{ "en_US@calendar=iso8601", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" },
|
||||
{ "en_US@calendar=iso8601", "Edjmm", "d, EEE, h:mm a" },
|
||||
{ "en_US@calendar=iso8601", "EdHmm", "d, EEE, HH:mm" },
|
||||
|
||||
{ "en_US", "EEEEyMMMMdjmm", "EEEE, MMMM d, y 'at' h:mm a" },
|
||||
{ "en_US", "EEEEyMMMMdHmm", "EEEE, MMMM d, y 'at' HH:mm" },
|
||||
{ "en_US", "Edjmm", "d EEE, h:mm a" },
|
||||
{ "en_US", "EdHmm", "d EEE, HH:mm" },
|
||||
};
|
||||
|
||||
for (String[] testCase : testCases) {
|
||||
String localeID = testCase[0];
|
||||
String skeleton = testCase[1];
|
||||
String expectedPattern = testCase[2];
|
||||
|
||||
DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance(new ULocale(localeID));
|
||||
|
||||
String actualPattern = dtpg.getBestPattern(skeleton);
|
||||
assertEquals("Wrong pattern for " + localeID + " and " + skeleton, expectedPattern, actualPattern);
|
||||
// if (!expectedPattern.equals(actualPattern)) {
|
||||
// System.out.println("Wrong pattern for " + localeID + " and " + skeleton + ": expected \"" + expectedPattern + "\", got \'" + actualPattern + "\"");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1194,6 +1194,9 @@ public class RelativeDateTimeFormatterTest extends CoreTestFmwk {
|
|||
RelativeDateTimeUnit.FRIDAY, enIN_decDef_short_midSent_friday),
|
||||
new TestRelativeDateTimeUnitItem("en_IN", -1, Style.SHORT, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
|
||||
RelativeDateTimeUnit.SATURDAY, enIN_decDef_short_midSent_saturday),
|
||||
|
||||
new TestRelativeDateTimeUnitItem("en@calendar=iso8601", -1, Style.LONG, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
|
||||
RelativeDateTimeUnit.SECOND, en_decDef_long_midSent_sec),
|
||||
};
|
||||
for (TestRelativeDateTimeUnitItem item: items) {
|
||||
ULocale uloc = new ULocale(item.localeID);
|
||||
|
|
Loading…
Add table
Reference in a new issue