Search in sources :

Example 56 with ParsePosition

use of java.text.ParsePosition 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));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 57 with ParsePosition

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

the class TestSettingsParser method test_parse_changeStyle_lenient.

public void test_parse_changeStyle_lenient() throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    getFormatter().parseUnresolved("a", pos);
    assertEquals(pos.getIndex(), 0);
}
Also used : ParsePosition(java.text.ParsePosition)

Example 58 with ParsePosition

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

the class TestSettingsParser method test_parse_changeStyle_sensitive.

/*
    public void test_print_nulls() throws Exception {
        setCaseSensitive(true);
        getFormatter().formatTo(null, null);
    }
    */
//-----------------------------------------------------------------------
public void test_parse_changeStyle_sensitive() throws Exception {
    setCaseSensitive(true);
    ParsePosition pos = new ParsePosition(0);
    getFormatter().parseUnresolved("a", pos);
    assertEquals(pos.getIndex(), 0);
}
Also used : ParsePosition(java.text.ParsePosition)

Example 59 with ParsePosition

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

the class TestStringLiteralParser method test_parse_error.

@Test(dataProvider = "error")
public void test_parse_error(String s, String text, int pos, Class<?> expected) {
    try {
        ParsePosition ppos = new ParsePosition(pos);
        getFormatter(s).parseUnresolved(text, ppos);
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isInstance(ex));
    }
}
Also used : ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 60 with ParsePosition

use of java.text.ParsePosition 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);
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) 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