ICU-11861 Added immutable lists of skeletons for iteration, as @internal. Also added test to make sure that they are aligned with what is tested. Note that I reordered and added items to DateFormatTest to verify coverage and order.
X-SVN-Rev: 37984
This commit is contained in:
parent
72e1610789
commit
09b798d757
@ -12,9 +12,13 @@ import java.text.FieldPosition;
|
||||
import java.text.Format;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
@ -1052,6 +1056,41 @@ public abstract class DateFormat extends UFormat {
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public static final String NUM_MONTH_WEEKDAY_DAY = "MEd";
|
||||
|
||||
/**
|
||||
* List of all of the date skeleton constants for iteration.
|
||||
* Note that this is fragile; be sure to add any values that are added above.
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final List<String> DATE_SKELETONS = Arrays.asList(
|
||||
YEAR,
|
||||
QUARTER,
|
||||
ABBR_QUARTER,
|
||||
YEAR_QUARTER,
|
||||
YEAR_ABBR_QUARTER,
|
||||
MONTH,
|
||||
ABBR_MONTH,
|
||||
NUM_MONTH,
|
||||
YEAR_MONTH,
|
||||
YEAR_ABBR_MONTH,
|
||||
YEAR_NUM_MONTH,
|
||||
DAY,
|
||||
YEAR_MONTH_DAY,
|
||||
YEAR_ABBR_MONTH_DAY,
|
||||
YEAR_NUM_MONTH_DAY,
|
||||
WEEKDAY,
|
||||
ABBR_WEEKDAY,
|
||||
YEAR_MONTH_WEEKDAY_DAY,
|
||||
YEAR_ABBR_MONTH_WEEKDAY_DAY,
|
||||
YEAR_NUM_MONTH_WEEKDAY_DAY,
|
||||
MONTH_DAY,
|
||||
ABBR_MONTH_DAY,
|
||||
NUM_MONTH_DAY,
|
||||
MONTH_WEEKDAY_DAY,
|
||||
ABBR_MONTH_WEEKDAY_DAY,
|
||||
NUM_MONTH_WEEKDAY_DAY);
|
||||
|
||||
/*
|
||||
* TIMES
|
||||
@ -1117,7 +1156,25 @@ public abstract class DateFormat extends UFormat {
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
public static final String MINUTE_SECOND = "ms";
|
||||
|
||||
|
||||
/**
|
||||
* List of all of the time skeleton constants for iteration.
|
||||
* Note that this is fragile; be sure to add any values that are added above.
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final List<String> TIME_SKELETONS = Arrays.asList(
|
||||
HOUR,
|
||||
HOUR24,
|
||||
MINUTE,
|
||||
HOUR_MINUTE,
|
||||
HOUR24_MINUTE,
|
||||
SECOND,
|
||||
HOUR_MINUTE_SECOND,
|
||||
HOUR24_MINUTE_SECOND,
|
||||
MINUTE_SECOND);
|
||||
|
||||
/*
|
||||
* TIMEZONES
|
||||
*/
|
||||
@ -1176,6 +1233,21 @@ public abstract class DateFormat extends UFormat {
|
||||
*/
|
||||
public static final String ABBR_UTC_TZ = "ZZZZ";
|
||||
|
||||
/**
|
||||
* List of all of the zone skeleton constants for iteration.
|
||||
* Note that this is fragile; be sure to add any values that are added above.
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final List<String> ZONE_SKELETONS = Arrays.asList(
|
||||
LOCATION_TZ,
|
||||
GENERIC_TZ,
|
||||
ABBR_GENERIC_TZ,
|
||||
SPECIFIC_TZ,
|
||||
ABBR_SPECIFIC_TZ,
|
||||
ABBR_UTC_TZ);
|
||||
|
||||
/*
|
||||
* deprecated skeleton constants
|
||||
*/
|
||||
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -76,27 +77,32 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
{DateFormat.YEAR_QUARTER, "yQQQQ", "en", "QQQQ y"},
|
||||
{DateFormat.YEAR_ABBR_QUARTER, "yQQQ", "en", "QQQ y"},
|
||||
|
||||
{DateFormat.NUM_MONTH, "M", "en", "L"},
|
||||
{DateFormat.ABBR_MONTH, "MMM", "en", "LLL"},
|
||||
{DateFormat.MONTH, "MMMM", "en", "LLLL"},
|
||||
{DateFormat.YEAR_NUM_MONTH, "yM","en","M/y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH, "yMMM","en","MMM y"},
|
||||
{DateFormat.ABBR_MONTH, "MMM", "en", "LLL"},
|
||||
{DateFormat.NUM_MONTH, "M", "en", "L"},
|
||||
{DateFormat.YEAR_MONTH, "yMMMM","en","MMMM y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH, "yMMM","en","MMM y"},
|
||||
{DateFormat.YEAR_NUM_MONTH, "yM","en","M/y"},
|
||||
|
||||
{DateFormat.DAY, "d","en","d"},
|
||||
{DateFormat.YEAR_NUM_MONTH_DAY, "yMd", "en", "M/d/y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH_DAY, "yMMMd", "en", "MMM d, y"},
|
||||
{DateFormat.YEAR_MONTH_DAY, "yMMMMd", "en", "MMMM d, y"},
|
||||
{DateFormat.YEAR_NUM_MONTH_WEEKDAY_DAY, "yMEd", "en", "EEE, M/d/y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH_WEEKDAY_DAY, "yMMMEd", "en", "EEE, MMM d, y"},
|
||||
{DateFormat.YEAR_MONTH_WEEKDAY_DAY, "yMMMMEEEEd", "en", "EEEE, MMMM d, y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH_DAY, "yMMMd", "en", "MMM d, y"},
|
||||
{DateFormat.YEAR_NUM_MONTH_DAY, "yMd", "en", "M/d/y"},
|
||||
|
||||
{DateFormat.WEEKDAY, "EEEE", "en", "cccc"},
|
||||
{DateFormat.ABBR_WEEKDAY, "E", "en", "ccc"},
|
||||
|
||||
{DateFormat.YEAR_MONTH_WEEKDAY_DAY, "yMMMMEEEEd", "en", "EEEE, MMMM d, y"},
|
||||
{DateFormat.YEAR_ABBR_MONTH_WEEKDAY_DAY, "yMMMEd", "en", "EEE, MMM d, y"},
|
||||
{DateFormat.YEAR_NUM_MONTH_WEEKDAY_DAY, "yMEd", "en", "EEE, M/d/y"},
|
||||
|
||||
{DateFormat.NUM_MONTH_DAY, "Md","en","M/d"},
|
||||
{DateFormat.ABBR_MONTH_DAY, "MMMd","en","MMM d"},
|
||||
{DateFormat.MONTH_DAY, "MMMMd","en","MMMM d"},
|
||||
{DateFormat.NUM_MONTH_WEEKDAY_DAY, "MEd","en","EEE, M/d"},
|
||||
{DateFormat.ABBR_MONTH_WEEKDAY_DAY, "MMMEd","en","EEE, MMM d"},
|
||||
{DateFormat.ABBR_MONTH_DAY, "MMMd","en","MMM d"},
|
||||
{DateFormat.NUM_MONTH_DAY, "Md","en","M/d"},
|
||||
|
||||
{DateFormat.MONTH_WEEKDAY_DAY, "MMMMEEEEd","en","EEEE, MMMM d"},
|
||||
{DateFormat.ABBR_MONTH_WEEKDAY_DAY, "MMMEd","en","EEE, MMM d"},
|
||||
{DateFormat.NUM_MONTH_WEEKDAY_DAY, "MEd","en","EEE, M/d"},
|
||||
|
||||
{DateFormat.HOUR, "j", "en", "h a"}, // (fixed expected result per ticket 6872<-6626)
|
||||
{DateFormat.HOUR24, "H", "en", "HH"}, // (fixed expected result per ticket 6872<-6626
|
||||
@ -117,15 +123,31 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
{DateFormat.ABBR_SPECIFIC_TZ, "z", "en", "z"},
|
||||
{DateFormat.ABBR_UTC_TZ, "ZZZZ", "en", "ZZZZ"},
|
||||
|
||||
{}, // marker for starting combinations
|
||||
|
||||
{DateFormat.YEAR_NUM_MONTH_DAY + DateFormat.ABBR_UTC_TZ, "yMdZZZZ", "en", "M/d/y, ZZZZ"},
|
||||
{DateFormat.MONTH_DAY + DateFormat.LOCATION_TZ, "MMMMdVVVV", "en", "MMMM d, VVVV"},
|
||||
};
|
||||
Date testDate = new Date(2012-1900, 6, 1, 14, 58, 59); // just for verbose log
|
||||
|
||||
|
||||
List<String> expectedSkeletons = new ArrayList<String>(DateFormat.DATE_SKELETONS);
|
||||
expectedSkeletons.addAll(DateFormat.TIME_SKELETONS);
|
||||
expectedSkeletons.addAll(DateFormat.ZONE_SKELETONS);
|
||||
boolean combinations = false;
|
||||
|
||||
List<String> testedSkeletons = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < EXPECTED.length; i++) {
|
||||
if (EXPECTED[i].length == 0) {
|
||||
combinations = true;
|
||||
continue;
|
||||
}
|
||||
boolean ok = true;
|
||||
// Verify that patterns have the correct values
|
||||
String actualPattern = EXPECTED[i][0];
|
||||
if (!combinations) {
|
||||
testedSkeletons.add(actualPattern);
|
||||
}
|
||||
String expectedPattern = EXPECTED[i][1];
|
||||
ULocale locale = new ULocale(EXPECTED[i][2], "", "");
|
||||
if (!actualPattern.equals(expectedPattern)) {
|
||||
@ -158,6 +180,9 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
logln(date1.format(testDate) + "\t\t" + Arrays.asList(EXPECTED[i]));
|
||||
}
|
||||
}
|
||||
assertEquals("All skeletons are tested (and in an iterable list)",
|
||||
new HashSet<String>(expectedSkeletons), new HashSet<String>(testedSkeletons));
|
||||
assertEquals("All skeletons are tested (and in an iterable list), and in the right order.", expectedSkeletons, testedSkeletons);
|
||||
}
|
||||
|
||||
// Test written by Wally Wedel and emailed to me.
|
||||
|
Loading…
Reference in New Issue
Block a user