Search in sources :

Example 46 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_parseUnresolved_StringParsePosition_parseError.

@Test
public void test_parseUnresolved_StringParsePosition_parseError() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 47 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_nullString.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullString() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    format.parseObject((String) null, pos);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 48 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_parse_CharSequence_ParsePosition_resolved.

@Test
public void test_parse_CharSequence_ParsePosition_resolved() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos);
    assertEquals(pos.getIndex(), 13);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(YEAR), true);
    assertEquals(result.isSupported(MONTH_OF_YEAR), true);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
    assertEquals(result.getLong(YEAR), 2012L);
    assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 49 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TestNumberParser method test_parseDigitsLenient.

@Test(dataProvider = "parseDigitsLenient")
public void test_parseDigitsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 50 with ParsePosition

use of java.text.ParsePosition in project jdk8u_jdk by JetBrains.

the class TestNumberParser method test_parseSignsLenient.

@Test(dataProvider = "parseSignsLenient")
public void test_parseSignsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parseVal);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Aggregations

ParsePosition (java.text.ParsePosition)694 Test (org.junit.Test)250 Date (java.util.Date)213 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)117 DateTimeFormatter (java.time.format.DateTimeFormatter)94 Test (org.testng.annotations.Test)88 ParseException (java.text.ParseException)71 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)49 SimpleDateFormat (android.icu.text.SimpleDateFormat)39 FieldPosition (java.text.FieldPosition)32 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Calendar (java.util.Calendar)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17