java.time.format.SignStyle Java Examples

The following examples show how to use java.time.format.SignStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestNumberParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseData")
public void test_parse_fresh(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_MONTH, 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_MONTH), expectedValue);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #2
Source File: TestNumberPrinter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.EXCEEDS_PAD).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
            return;  // unreachable
        }
        if (result.length() > minPad || value < 0) {
            result = (value < 0 ? "-" + result : "+" + result);
        }
        assertEquals(buf.toString(), result);
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
 
Example #3
Source File: TestNumberParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #4
Source File: TCKSignStyle.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
                                         .toFormatter();
    formatter = formatter.withZone(ZoneOffset.UTC);
    if (expectedEx == null) {
        String output = formatter.format(localDate);
        assertEquals(output, expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example #5
Source File: TestNumberParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: TestNumberParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #7
Source File: TCKSignStyle.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
                                         .toFormatter();
    formatter = formatter.withZone(ZoneOffset.UTC);
    if (expectedEx == null) {
        String output = formatter.format(localDate);
        assertEquals(output, expectedStr);
    } else {
        try {
            formatter.format(localDate);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
 
Example #8
Source File: TestNumberParser.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
    setStrict(false);
    ParsePosition pos = new ParsePosition(0);
    DateTimeFormatter f = builder
            .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
            .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
    TemporalAccessor parsed = f.parseUnresolved(input, pos);
    if (pos.getErrorIndex() != -1) {
        assertEquals(pos.getErrorIndex(), parseLen);
    } else {
        assertEquals(pos.getIndex(), parseLen);
        assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
        assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
        assertEquals(parsed.query(TemporalQueries.chronology()), null);
        assertEquals(parsed.query(TemporalQueries.zoneId()), null);
    }
}
 
Example #9
Source File: TestNumberParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #10
Source File: TestNumberParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="error")
public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
    try {
        getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isInstance(ex));
    }
}
 
Example #11
Source File: TCKPadPrinterParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_parse_decoratedStartsWithPad_number() {
    builder.padNext(3, '-').appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL);
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--2", pos);
    assertEquals(pos.getIndex(), 3);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 2L);  // +2, not -2
}
 
Example #12
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #13
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #14
Source File: TCKSignStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
            {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},

            {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
            {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
            {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},

            {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
    };
}
 
Example #15
Source File: TestNumberParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #16
Source File: TestNumberParser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="error")
public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
    try {
        getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
        fail();
    } catch (RuntimeException ex) {
        assertTrue(expected.isInstance(ex));
    }
}
 
Example #17
Source File: TestNumberPrinter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="Pad")
public void test_pad_NORMAL(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NORMAL).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), (value < 0 ? "-" + result : result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
 
Example #18
Source File: TestDateTimeFormatterBuilder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #19
Source File: TestNumberPrinter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="Pad")
public void test_pad_ALWAYS(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.ALWAYS).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), (value < 0 ? "-" + result : "+" + result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
 
Example #20
Source File: TestNumberParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="error")
Object[][] data_error() {
    return new Object[][] {
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", -1, IndexOutOfBoundsException.class},
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", 3, IndexOutOfBoundsException.class},
    };
}
 
Example #21
Source File: TestDateTimeFormatterBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent3_parse6() throws Exception {
    builder
        .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
        .appendValue(MONTH_OF_YEAR, 2)
        .appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(Year,4,10,EXCEEDS_PAD)Value(MonthOfYear,2)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("20090630", new ParsePosition(0));
    assertEquals(parsed.getLong(YEAR), 2009L);
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 30L);
}
 
Example #22
Source File: TestNumberParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="error")
Object[][] data_error() {
    return new Object[][] {
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", -1, IndexOutOfBoundsException.class},
        {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", 3, IndexOutOfBoundsException.class},
    };
}
 
Example #23
Source File: StrfTimeToDateTimeFormatter.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Override
public void enterPs(StrfTimeParser.PsContext ctx) {
    // %s   The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
    // Based upon https://stackoverflow.com/questions/36066155/datetimeformatter-for-epoch-milliseconds#answer-36069732
    builder
        .appendValue(ChronoField.INSTANT_SECONDS, 1, 19, SignStyle.NEVER);
}
 
Example #24
Source File: TestNumberPrinter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="Pad")
public void test_pad_ALWAYS(int minPad, int maxPad, long value, String result) throws Exception {
    try {
        getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.ALWAYS).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
        if (result == null) {
            fail("Expected exception");
        }
        assertEquals(buf.toString(), (value < 0 ? "-" + result : "+" + result));
    } catch (DateTimeException ex) {
        if (result != null) {
            throw ex;
        }
        assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
    }
}
 
Example #25
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse5() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2).appendLiteral('4');
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)'4'");
    TemporalAccessor parsed = f.parseUnresolved("01234", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}
 
Example #26
Source File: TCKSignStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
            {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},

            {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
            {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
            {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},

            {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
    };
}
 
Example #27
Source File: TestNumberParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="parseSignsStrict")
public void test_parseSignsStrict(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
    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);
    }
}
 
Example #28
Source File: TCKSignStyle.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
    return new Object[][] {
            {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
            {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},

            {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
            {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},

            {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
            {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
            {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},

            {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
            {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
    };
}
 
Example #29
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent3_parse6() throws Exception {
    builder
        .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
        .appendValue(MONTH_OF_YEAR, 2)
        .appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(Year,4,10,EXCEEDS_PAD)Value(MonthOfYear,2)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("20090630", new ParsePosition(0));
    assertEquals(parsed.getLong(YEAR), 2009L);
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 30L);
}
 
Example #30
Source File: TestDateTimeFormatterBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_appendValue_subsequent2_parse4() throws Exception {
    builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
    DateTimeFormatter f = builder.toFormatter();
    assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
    TemporalAccessor parsed = f.parseUnresolved("0123", new ParsePosition(0));
    assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
    assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}