use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_parseLenient.
//-----------------------------------------------------------------------
// Parsing tests for lenient mode
//-----------------------------------------------------------------------
@Test(dataProvider = "ParseLenientSensitive")
public void test_parseLenient(TemporalField field, int minWidth, int maxWidth, int baseValue, String input, int pos, Pair strict, Pair lenient) {
ParsePosition ppos = new ParsePosition(pos);
setStrict(false);
TemporalAccessor parsed = getFormatter0(field, minWidth, maxWidth, baseValue).parseUnresolved(input, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), lenient.parseLen, "error case parse position");
assertEquals(parsed, lenient.parseVal, "unexpected parse result");
} else {
assertEquals(ppos.getIndex(), lenient.parseLen, "parse position");
assertParsed(parsed, YEAR, lenient.parseVal != null ? (long) lenient.parseVal : null);
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_parseAllLenient.
@Test(dataProvider = "ParseAll")
public void test_parseAllLenient(TemporalField field, int width, int baseValue, String input, int pos, int parseLen, Integer parseVal) {
ParsePosition ppos = new ParsePosition(pos);
setStrict(false);
TemporalAccessor parsed = getFormatter0(field, width, baseValue).parseUnresolved(input, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
assertEquals(parsed, parseVal, "unexpected parse result");
} else {
assertEquals(ppos.getIndex(), parseLen, "parse position");
assertParsed(parsed, YEAR, parseVal != null ? (long) parseVal : null);
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_parseAdjacent.
@Test(dataProvider = "ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
ParsePosition ppos = new ParsePosition(0);
builder = new DateTimeFormatterBuilder();
setStrict(strict);
builder.appendPattern(pattern);
DateTimeFormatter dtf = builder.toFormatter();
TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
} else {
assertEquals(ppos.getIndex(), parseLen, "parse position");
assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
}
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestNonIsoFormatter method test_parseLocalizedText.
@Test(dataProvider = "format_data")
public void test_parseLocalizedText(Chronology chrono, Locale formatLocale, Locale numberingLocale, ChronoLocalDate expected, String text) {
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).withChronology(chrono).withLocale(formatLocale).withDecimalStyle(DecimalStyle.of(numberingLocale));
TemporalAccessor temporal = dtf.parse(text);
ChronoLocalDate date = chrono.date(temporal);
assertEquals(date, expected);
}
use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.
the class TestNumberParser method test_parse_textField.
@Test(dataProvider = "parseData")
public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
ParsePosition ppos = new ParsePosition(pos);
DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
if (subsequentWidth > 0) {
// hacky, to reserve space
dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
}
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), expectedPos);
} else {
assertTrue(subsequentWidth >= 0);
assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
Aggregations