--- old/test/java/time/tck/java/time/format/TCKLocalizedFieldParser.java 2013-04-11 23:17:42.000000000 -0700 +++ new/test/java/time/tck/java/time/format/TCKLocalizedFieldParser.java 2013-04-11 23:17:42.000000000 -0700 @@ -59,8 +59,7 @@ */ package tck.java.time.format; -import static java.time.temporal.ChronoField.MONTH_OF_YEAR; -import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.testng.Assert.assertEquals; import java.text.ParsePosition; @@ -78,7 +77,7 @@ /** * Test TCKLocalizedFieldParser. */ -@Test(groups={"tck"}) +@Test public class TCKLocalizedFieldParser extends AbstractTestPrinterParser { //----------------------------------------------------------------------- @@ -86,13 +85,16 @@ Object[][] provider_fieldPatterns() { return new Object[][] { {"e", "6", 0, 1, 6}, - {"w", "3", 0, 1, 3}, - {"W", "29", 0, 2, 29}, - {"WW", "29", 0, 2, 29}, + {"W", "3", 0, 1, 3}, + {"w", "29", 0, 2, 29}, + {"ww", "29", 0, 2, 29}, + {"Y", "2013", 0, 4, 2013}, + {"YY", "13", 0, 2, 2013}, + {"YYYY", "2013", 0, 4, 2013}, }; } - @Test(dataProvider="FieldPatterns",groups={"tck"}) + @Test(dataProvider="FieldPatterns") public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) { WeekFields weekDef = WeekFields.of(locale); TemporalField field = null; @@ -101,10 +103,13 @@ field = weekDef.dayOfWeek(); break; case 'w': - field = weekDef.weekOfMonth(); + field = weekDef.weekOfWeekBasedYear(); break; case 'W': - field = weekDef.weekOfYear(); + field = weekDef.weekOfMonth(); + break; + case 'Y': + field = weekDef.weekBasedYear(); break; default: throw new IllegalStateException("bad format letter from pattern"); @@ -123,27 +128,24 @@ } } - //----------------------------------------------------------------------- - @DataProvider(name="LocalDatePatterns") + //----------------------------------------------------------------------- + @DataProvider(name="LocalWeekMonthYearPatterns") Object[][] provider_patternLocalDate() { return new Object[][] { - {"e w M y", "1 1 1 2012", 0, 10, LocalDate.of(2012, 1, 1)}, - {"e w M y", "1 2 1 2012", 0, 10, LocalDate.of(2012, 1, 8)}, - {"e w M y", "2 2 1 2012", 0, 10, LocalDate.of(2012, 1, 9)}, - {"e w M y", "3 2 1 2012", 0, 10, LocalDate.of(2012, 1, 10)}, - {"e w M y", "1 3 1 2012", 0, 10, LocalDate.of(2012, 1, 15)}, - {"e w M y", "2 3 1 2012", 0, 10, LocalDate.of(2012, 1, 16)}, - {"e w M y", "6 2 1 2012", 0, 10, LocalDate.of(2012, 1, 13)}, - {"e w M y", "6 2 7 2012", 0, 10, LocalDate.of(2012, 7, 13)}, - {"e W y", "6 29 2012", 0, 9, LocalDate.of(2012, 7, 20)}, - {"'Date: 'y-MM', day-of-week: 'e', week-of-month: 'w", + {"e W M y", "1 1 1 2012", 0, 10, LocalDate.of(2012, 1, 1)}, + {"e W M y", "1 2 1 2012", 0, 10, LocalDate.of(2012, 1, 8)}, + {"e W M y", "2 2 1 2012", 0, 10, LocalDate.of(2012, 1, 9)}, + {"e W M y", "3 2 1 2012", 0, 10, LocalDate.of(2012, 1, 10)}, + {"e W M y", "1 3 1 2012", 0, 10, LocalDate.of(2012, 1, 15)}, + {"e W M y", "2 3 1 2012", 0, 10, LocalDate.of(2012, 1, 16)}, + {"e W M y", "6 2 1 2012", 0, 10, LocalDate.of(2012, 1, 13)}, + {"e W M y", "6 2 7 2012", 0, 10, LocalDate.of(2012, 7, 13)}, + {"'Date: 'y-MM', day-of-week: 'e', week-of-month: 'W", "Date: 2012-07, day-of-week: 6, week-of-month: 3", 0, 47, LocalDate.of(2012, 7, 20)}, - {"'Date: 'y', day-of-week: 'e', week-of-year: 'W", - "Date: 2012, day-of-week: 6, week-of-year: 29", 0, 44, LocalDate.of(2012, 7, 20)}, }; } - @Test(dataProvider="LocalDatePatterns",groups={"tck"}) + @Test(dataProvider="LocalWeekMonthYearPatterns") public void test_parse_textLocalDate(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) { ParsePosition ppos = new ParsePosition(pos); DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern); @@ -153,7 +155,7 @@ assertEquals(ppos.getErrorIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); - assertEquals(parsed.isSupported(YEAR), true); + assertEquals(parsed.isSupported(YEAR_OF_ERA), true); assertEquals(parsed.isSupported(WeekFields.of(locale).dayOfWeek()), true); assertEquals(parsed.isSupported(WeekFields.of(locale).weekOfMonth()) || parsed.isSupported(WeekFields.of(locale).weekOfYear()), true); @@ -163,4 +165,41 @@ } } + //----------------------------------------------------------------------- + @DataProvider(name="LocalWeekBasedYearPatterns") + Object[][] provider_patternLocalWeekBasedYearDate() { + return new Object[][] { + //{"w Y", "29 2012", 0, 7, LocalDate.of(2012, 7, 20)}, // Default lenient dayOfWeek not supported + {"e w Y", "6 29 2012", 0, 9, LocalDate.of(2012, 7, 20)}, + {"'Date: 'Y', day-of-week: 'e', week-of-year: 'w", + "Date: 2012, day-of-week: 6, week-of-year: 29", 0, 44, LocalDate.of(2012, 7, 20)}, + {"Y-w-e", "2008-01-1", 0, 9, LocalDate.of(2007, 12, 30)}, + {"Y-w-e", "2008-52-1", 0, 9, LocalDate.of(2008, 12, 21)}, + {"Y-w-e", "2008-52-7", 0, 9, LocalDate.of(2008, 12, 27)}, + {"Y-w-e", "2009-01-01", 0, 10, LocalDate.of(2008, 12, 28)}, + {"Y-w-e", "2009-01-04", 0, 10, LocalDate.of(2008, 12, 31)}, + {"Y-w-e", "2009-01-05", 0, 10, LocalDate.of(2009, 1, 1)}, + }; + } + + @Test(dataProvider="LocalWeekBasedYearPatterns") + public void test_parse_WeekBasedYear(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) { + ParsePosition ppos = new ParsePosition(pos); + DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern); + DateTimeFormatter dtf = b.toFormatter(locale); + TemporalAccessor parsed = dtf.parseUnresolved(text, ppos); + if (ppos.getErrorIndex() != -1) { + assertEquals(ppos.getErrorIndex(), expectedPos); + } else { + WeekFields weekDef = WeekFields.of(locale); + assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position"); + assertEquals(parsed.isSupported(weekDef.dayOfWeek()), pattern.indexOf('e') >= 0); + assertEquals(parsed.isSupported(weekDef.weekOfWeekBasedYear()), pattern.indexOf('w') >= 0); + assertEquals(parsed.isSupported(weekDef.weekBasedYear()), pattern.indexOf('Y') >= 0); + // ensure combination resolves into a date + LocalDate result = LocalDate.parse(text, dtf); + assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern + ", weekDef: " + weekDef); + } + } + }