use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_reducedWithLateChronoChangeTwice.
@Test
public void test_reducedWithLateChronoChangeTwice() {
DateTimeFormatter df = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1)).appendLiteral(" ").appendChronologyId().appendLiteral(" ").appendChronologyId().toFormatter();
int expected = 2044;
String input = "44 ThaiBuddhist ISO";
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = df.parseUnresolved(input, pos);
assertEquals(pos.getIndex(), input.length(), "Input not parsed completely: " + pos);
assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)");
int actual = parsed.get(YEAR);
assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", parsed.query(TemporalQueries.chronology()), input));
}
use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_parseLenient_baseDate.
@Test(dataProvider = "ParseLenientSensitive")
public void test_parseLenient_baseDate(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 = getFormatterBaseDate(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.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_parseStrict.
//-----------------------------------------------------------------------
// Parsing tests for strict mode
//-----------------------------------------------------------------------
@Test(dataProvider = "ParseLenientSensitive")
public void test_parseStrict(TemporalField field, int minWidth, int maxWidth, int baseValue, String input, int pos, Pair strict, Pair lenient) {
ParsePosition ppos = new ParsePosition(pos);
setStrict(true);
TemporalAccessor parsed = getFormatter0(field, minWidth, maxWidth, baseValue).parseUnresolved(input, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), strict.parseLen, "error case parse position");
assertEquals(parsed, strict.parseVal, "unexpected parse result");
} else {
assertEquals(ppos.getIndex(), strict.parseLen, "parse position");
assertParsed(parsed, YEAR, strict.parseVal != null ? (long) strict.parseVal : null);
}
}
use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestFractionPrinterParser method test_reverseParse_preceededByNonDigit.
// @Test(dataProvider="Nanos")
// public void test_reverseParse_followedByNonDigit_noDecimalPoint(int minWidth, int maxWidth, int value, String result) throws Exception {
// FractionPrinterParser pp = new FractionPrinterParser(NANO_OF_SECOND, minWidth, maxWidth, false);
// int newPos = pp.parse(parseContext, result + " ", (result.startsWith(".") ? 1 : 0));
// assertEquals(newPos, result.length());
// int expectedValue = fixParsedValue(maxWidth, value);
// assertParsed(parseContext, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
// }
@Test(dataProvider = "Nanos")
public void test_reverseParse_preceededByNonDigit(int minWidth, int maxWidth, int value, String result) throws Exception {
ParsePosition pos = new ParsePosition(1);
int expectedValue = fixParsedValue(maxWidth, value);
TemporalAccessor parsed = getFormatter(NANO_OF_SECOND, minWidth, maxWidth, true).parseUnresolved(" " + result, pos);
assertEquals(pos.getIndex(), result.length() + 1);
assertParsed(parsed, NANO_OF_SECOND, value == 0 && minWidth == 0 ? null : (long) expectedValue);
}
use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestTextParser method test_parseDayOfWeekText.
@Test(dataProvider = "parseDayOfWeekText")
public void test_parseDayOfWeekText(Locale locale, String pattern, String input, DayOfWeek expected) {
DateTimeFormatter formatter = getPatternFormatter(pattern).withLocale(locale);
ParsePosition pos = new ParsePosition(0);
assertEquals(DayOfWeek.from(formatter.parse(input, pos)), expected);
assertEquals(pos.getIndex(), input.length());
}
Aggregations