Search in sources :

Example 36 with ParsePosition

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

the class TestZoneOffsetParser method test_parse_invalid.

@Test(dataProvider = "badOffsets")
public void test_parse_invalid(String pattern, String parse, int expectedPosition) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(pattern, "Z").parseUnresolved(parse, pos);
    assertEquals(pos.getErrorIndex(), expectedPosition);
    assertEquals(parsed, null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 37 with ParsePosition

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

the class TestZoneOffsetParser method test_parse_exactMatch_EmptyUTC.

@Test(dataProvider = "offsets")
public void test_parse_exactMatch_EmptyUTC(String pattern, String parse, ZoneOffset expected) throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter(pattern, "").parseUnresolved(parse, pos);
    assertEquals(pos.getIndex(), parse.length());
    assertParsed(parsed, expected);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 38 with ParsePosition

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

the class TestZoneOffsetParser method test_parse_exactMatch_UTC.

//-----------------------------------------------------------------------
public void test_parse_exactMatch_UTC() throws Exception {
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter("+HH:MM:ss", "Z").parseUnresolved("Z", pos);
    assertEquals(pos.getIndex(), 1);
    assertParsed(parsed, ZoneOffset.UTC);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition)

Example 39 with ParsePosition

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

the class TestZoneOffsetParser method test_parse_caseInsensitiveUTC_unmatchedCase.

public void test_parse_caseInsensitiveUTC_unmatchedCase() throws Exception {
    setCaseSensitive(false);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = getFormatter("+HH:MM:ss", "Z").parseUnresolved("z", pos);
    assertEquals(pos.getIndex(), 1);
    assertParsed(parsed, ZoneOffset.UTC);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition)

Example 40 with ParsePosition

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

the class TestTextParser method test_parse_noMatch_atEnd.

public void test_parse_noMatch_atEnd() throws Exception {
    ParsePosition pos = new ParsePosition(6);
    TemporalAccessor parsed = getFormatter(DAY_OF_WEEK, TextStyle.FULL).parseUnresolved("Monday", pos);
    assertEquals(pos.getErrorIndex(), 6);
    assertEquals(parsed, null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition)

Aggregations

ParsePosition (java.text.ParsePosition)704 Test (org.junit.Test)253 Date (java.util.Date)221 TemporalAccessor (java.time.temporal.TemporalAccessor)163 SimpleDateFormat (java.text.SimpleDateFormat)125 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 Calendar (java.util.Calendar)26 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)25 Calendar (android.icu.util.Calendar)23 ULocale (android.icu.util.ULocale)23 NumberFormat (java.text.NumberFormat)23 Format (java.text.Format)21 DecimalFormat (java.text.DecimalFormat)19 GregorianCalendar (android.icu.util.GregorianCalendar)18 JapaneseCalendar (android.icu.util.JapaneseCalendar)17