use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestTextParser method test_parse_short_strict_number_noMatch.
public void test_parse_short_strict_number_noMatch() throws Exception {
setStrict(true);
ParsePosition pos = new ParsePosition(0);
getFormatter(MONTH_OF_YEAR, TextStyle.SHORT).parseUnresolved("1", pos);
assertEquals(pos.getErrorIndex(), 0);
}
use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestTextParser method test_parse_strict_caseSensitive_parseUpper.
//-----------------------------------------------------------------------
@Test(dataProvider = "parseText")
public void test_parse_strict_caseSensitive_parseUpper(TemporalField field, TextStyle style, int value, String input) throws Exception {
if (input.equals(input.toUpperCase(Locale.ROOT))) {
// Skip if the given input is all upper case (e.g., "Q1")
return;
}
setCaseSensitive(true);
ParsePosition pos = new ParsePosition(0);
getFormatter(field, style).parseUnresolved(input.toUpperCase(Locale.ROOT), pos);
assertEquals(pos.getErrorIndex(), 0);
}
use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.
the class TestTextParser method test_parseText.
@Test(dataProvider = "parseText")
public void test_parseText(TemporalField field, TextStyle style, int value, String input) throws Exception {
ParsePosition pos = new ParsePosition(0);
assertEquals(getFormatter(field, style).parseUnresolved(input, pos).getLong(field), (long) value);
assertEquals(pos.getIndex(), input.length());
}
use of java.text.ParsePosition in project lucene-solr by apache.
the class NumberFormatTransformer method parseNumber.
private Number parseNumber(String val, NumberFormat numFormat) throws ParseException {
ParsePosition parsePos = new ParsePosition(0);
Number num = numFormat.parse(val, parsePos);
if (parsePos.getIndex() != val.length()) {
throw new ParseException("illegal number format", parsePos.getIndex());
}
return num;
}
use of java.text.ParsePosition in project logging-log4j2 by apache.
the class FastDateParser_MoreOrLessTest method testInputHasWhitespace.
@Test
public void testInputHasWhitespace() {
final FastDateParser parser = new FastDateParser("M/d/y", TimeZone.getDefault(), Locale.getDefault());
//SimpleDateFormat parser = new SimpleDateFormat("M/d/y");
final ParsePosition parsePosition = new ParsePosition(0);
final Date date = parser.parse(" 3/ 23/ 1961", parsePosition);
Assert.assertEquals(12, parsePosition.getIndex());
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Assert.assertEquals(1961, calendar.get(Calendar.YEAR));
Assert.assertEquals(2, calendar.get(Calendar.MONTH));
Assert.assertEquals(23, calendar.get(Calendar.DATE));
}
Aggregations