test/java/time/test/java/time/format/TestNumberParser.java

Print this page




  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package test.java.time.format;
  61 
  62 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  63 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  64 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  65 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  66 import static org.testng.Assert.assertEquals;
  67 import static org.testng.Assert.assertTrue;
  68 import static org.testng.Assert.fail;
  69 
  70 import java.text.ParsePosition;
  71 import java.time.format.DateTimeFormatter;
  72 import java.time.format.SignStyle;
  73 import java.time.temporal.Queries;
  74 import java.time.temporal.TemporalAccessor;
  75 import java.time.temporal.TemporalField;

  76 
  77 import org.testng.annotations.DataProvider;
  78 import org.testng.annotations.Test;
  79 
  80 /**
  81  * Test NumberPrinterParser.
  82  */
  83 @Test(groups={"implementation"})
  84 public class TestNumberParser extends AbstractTestPrinterParser {
  85 
  86     //-----------------------------------------------------------------------
  87     @DataProvider(name="error")
  88     Object[][] data_error() {
  89         return new Object[][] {
  90             {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", -1, IndexOutOfBoundsException.class},
  91             {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", 3, IndexOutOfBoundsException.class},
  92         };
  93     }
  94 
  95     @Test(dataProvider="error")
  96     public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
  97         try {
  98             getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
  99             fail();
 100         } catch (RuntimeException ex) {
 101             assertTrue(expected.isInstance(ex));
 102         }
 103     }


 161             {2, 19, SignStyle.NEVER, 2, "1AAAAABBBBBCCCCC", 0, 0, 0},
 162         };
 163     }
 164 
 165     //-----------------------------------------------------------------------
 166     @Test(dataProvider="parseData")
 167     public void test_parse_fresh(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
 168         ParsePosition ppos = new ParsePosition(pos);
 169         DateTimeFormatter dtf = getFormatter(DAY_OF_MONTH, minWidth, maxWidth, signStyle);
 170         if (subsequentWidth > 0) {
 171             // hacky, to reserve space
 172             dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withSymbols(symbols);
 173         }
 174         TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
 175         if (ppos.getErrorIndex() != -1) {
 176             assertEquals(ppos.getErrorIndex(), expectedPos);
 177         } else {
 178             assertTrue(subsequentWidth >= 0);
 179             assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
 180             assertEquals(parsed.getLong(DAY_OF_MONTH), expectedValue);
 181             assertEquals(parsed.query(Queries.chronology()), null);
 182             assertEquals(parsed.query(Queries.zoneId()), null);
 183         }
 184     }
 185 
 186     @Test(dataProvider="parseData")
 187     public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
 188         ParsePosition ppos = new ParsePosition(pos);
 189         DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
 190         if (subsequentWidth > 0) {
 191             // hacky, to reserve space
 192             dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withSymbols(symbols);
 193         }
 194         TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
 195         if (ppos.getErrorIndex() != -1) {
 196             assertEquals(ppos.getErrorIndex(), expectedPos);
 197         } else {
 198             assertTrue(subsequentWidth >= 0);
 199             assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
 200             assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
 201             assertEquals(parsed.query(Queries.chronology()), null);
 202             assertEquals(parsed.query(Queries.zoneId()), null);
 203         }
 204     }
 205 
 206     //-----------------------------------------------------------------------
 207     @DataProvider(name="parseSignsStrict")
 208     Object[][] provider_parseSignsStrict() {
 209         return new Object[][] {
 210             // basics
 211             {"0", 1, 2, SignStyle.NEVER, 1, 0},
 212             {"1", 1, 2, SignStyle.NEVER, 1, 1},
 213             {"2", 1, 2, SignStyle.NEVER, 1, 2},
 214             {"3", 1, 2, SignStyle.NEVER, 1, 3},
 215             {"4", 1, 2, SignStyle.NEVER, 1, 4},
 216             {"5", 1, 2, SignStyle.NEVER, 1, 5},
 217             {"6", 1, 2, SignStyle.NEVER, 1, 6},
 218             {"7", 1, 2, SignStyle.NEVER, 1, 7},
 219             {"8", 1, 2, SignStyle.NEVER, 1, 8},
 220             {"9", 1, 2, SignStyle.NEVER, 1, 9},
 221             {"10", 1, 2, SignStyle.NEVER, 2, 10},
 222             {"100", 1, 2, SignStyle.NEVER, 2, 10},


 296             {"-50", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 297             {"-500", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 298             {"-AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 299             {"+0", 1, 2, SignStyle.EXCEEDS_PAD, 0, null},
 300             {"+5", 1, 2, SignStyle.EXCEEDS_PAD, 0, null},
 301             {"+50", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 302             {"+500", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 303             {"+AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 304        };
 305     }
 306 
 307     @Test(dataProvider="parseSignsStrict")
 308     public void test_parseSignsStrict(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 309         ParsePosition pos = new ParsePosition(0);
 310         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 311         if (pos.getErrorIndex() != -1) {
 312             assertEquals(pos.getErrorIndex(), parseLen);
 313         } else {
 314             assertEquals(pos.getIndex(), parseLen);
 315             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 316             assertEquals(parsed.query(Queries.chronology()), null);
 317             assertEquals(parsed.query(Queries.zoneId()), null);
 318         }
 319     }
 320 
 321     //-----------------------------------------------------------------------
 322     @DataProvider(name="parseSignsLenient")
 323     Object[][] provider_parseSignsLenient() {
 324         return new Object[][] {
 325             // never
 326             {"0", 1, 2, SignStyle.NEVER, 1, 0},
 327             {"5", 1, 2, SignStyle.NEVER, 1, 5},
 328             {"50", 1, 2, SignStyle.NEVER, 2, 50},
 329             {"500", 1, 2, SignStyle.NEVER, 2, 50},
 330             {"-0", 1, 2, SignStyle.NEVER, 2, 0},
 331             {"-5", 1, 2, SignStyle.NEVER, 2, -5},
 332             {"-50", 1, 2, SignStyle.NEVER, 3, -50},
 333             {"-500", 1, 2, SignStyle.NEVER, 3, -50},
 334             {"-AAA", 1, 2, SignStyle.NEVER, 1, null},
 335             {"+0", 1, 2, SignStyle.NEVER, 2, 0},
 336             {"+5", 1, 2, SignStyle.NEVER, 2, 5},
 337             {"+50", 1, 2, SignStyle.NEVER, 3, 50},


 406             {"-500", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 407             {"-AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 408             {"+0", 1, 2, SignStyle.EXCEEDS_PAD, 2, 0},
 409             {"+5", 1, 2, SignStyle.EXCEEDS_PAD, 2, 5},
 410             {"+50", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 411             {"+500", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 412             {"+AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 413        };
 414     }
 415 
 416     @Test(dataProvider="parseSignsLenient")
 417     public void test_parseSignsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 418         setStrict(false);
 419         ParsePosition pos = new ParsePosition(0);
 420         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 421         if (pos.getErrorIndex() != -1) {
 422             assertEquals(pos.getErrorIndex(), parseLen);
 423         } else {
 424             assertEquals(pos.getIndex(), parseLen);
 425             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 426             assertEquals(parsed.query(Queries.chronology()), null);
 427             assertEquals(parsed.query(Queries.zoneId()), null);
 428         }
 429     }
 430 
 431     //-----------------------------------------------------------------------
 432     @DataProvider(name="parseDigitsLenient")
 433     Object[][] provider_parseDigitsLenient() {
 434         return new Object[][] {
 435                 // never
 436                 {"5", 1, 2, SignStyle.NEVER, 1, 5},
 437                 {"5", 2, 2, SignStyle.NEVER, 1, 5},
 438                 {"54", 1, 3, SignStyle.NEVER, 2, 54},
 439                 {"54", 2, 3, SignStyle.NEVER, 2, 54},
 440                 {"54", 3, 3, SignStyle.NEVER, 2, 54},
 441                 {"543", 1, 3, SignStyle.NEVER, 3, 543},
 442                 {"543", 2, 3, SignStyle.NEVER, 3, 543},
 443                 {"543", 3, 3, SignStyle.NEVER, 3, 543},
 444                 {"5432", 1, 3, SignStyle.NEVER, 3, 543},
 445                 {"5432", 2, 3, SignStyle.NEVER, 3, 543},
 446                 {"5432", 3, 3, SignStyle.NEVER, 3, 543},
 447                 {"5AAA", 2, 3, SignStyle.NEVER, 1, 5},


 497                 {"543", 1, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 498                 {"543", 2, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 499                 {"543", 3, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 500                 {"5432", 1, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 501                 {"5432", 2, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 502                 {"5432", 3, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 503                 {"5AAA", 2, 3, SignStyle.EXCEEDS_PAD, 1, 5},
 504         };
 505     }
 506 
 507     @Test(dataProvider="parseDigitsLenient")
 508     public void test_parseDigitsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 509         setStrict(false);
 510         ParsePosition pos = new ParsePosition(0);
 511         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 512         if (pos.getErrorIndex() != -1) {
 513             assertEquals(pos.getErrorIndex(), parseLen);
 514         } else {
 515             assertEquals(pos.getIndex(), parseLen);
 516             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 517             assertEquals(parsed.query(Queries.chronology()), null);
 518             assertEquals(parsed.query(Queries.zoneId()), null);
 519         }
 520     }
 521 
 522     //-----------------------------------------------------------------------
 523     @DataProvider(name="parseDigitsAdjacentLenient")
 524     Object[][] provider_parseDigitsAdjacentLenient() {
 525         return new Object[][] {
 526                 // never
 527                 {"5", 1, null, null},
 528                 {"54", 1, null, null},
 529 
 530                 {"543", 3, 5, 43},
 531                 {"543A", 3, 5, 43},
 532 
 533                 {"5432", 4, 54, 32},
 534                 {"5432A", 4, 54, 32},
 535 
 536                 {"54321", 4, 54, 32},
 537                 {"54321A", 4, 54, 32},
 538         };
 539     }
 540 
 541     @Test(dataProvider="parseDigitsAdjacentLenient")
 542     public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
 543         setStrict(false);
 544         ParsePosition pos = new ParsePosition(0);
 545         DateTimeFormatter f = builder
 546                 .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
 547                 .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withSymbols(symbols);
 548         TemporalAccessor parsed = f.parseUnresolved(input, pos);
 549         if (pos.getErrorIndex() != -1) {
 550             assertEquals(pos.getErrorIndex(), parseLen);
 551         } else {
 552             assertEquals(pos.getIndex(), parseLen);
 553             assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
 554             assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
 555             assertEquals(parsed.query(Queries.chronology()), null);
 556             assertEquals(parsed.query(Queries.zoneId()), null);
 557         }
 558     }
 559 
 560 }


  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package test.java.time.format;
  61 
  62 import static java.time.temporal.ChronoField.DAY_OF_MONTH;
  63 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  64 import static java.time.temporal.ChronoField.DAY_OF_YEAR;
  65 import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
  66 import static org.testng.Assert.assertEquals;
  67 import static org.testng.Assert.assertTrue;
  68 import static org.testng.Assert.fail;
  69 
  70 import java.text.ParsePosition;
  71 import java.time.format.DateTimeFormatter;
  72 import java.time.format.SignStyle;

  73 import java.time.temporal.TemporalAccessor;
  74 import java.time.temporal.TemporalField;
  75 import java.time.temporal.TemporalQuery;
  76 
  77 import org.testng.annotations.DataProvider;
  78 import org.testng.annotations.Test;
  79 
  80 /**
  81  * Test NumberPrinterParser.
  82  */
  83 @Test
  84 public class TestNumberParser extends AbstractTestPrinterParser {
  85 
  86     //-----------------------------------------------------------------------
  87     @DataProvider(name="error")
  88     Object[][] data_error() {
  89         return new Object[][] {
  90             {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", -1, IndexOutOfBoundsException.class},
  91             {DAY_OF_MONTH, 1, 2, SignStyle.NEVER, "12", 3, IndexOutOfBoundsException.class},
  92         };
  93     }
  94 
  95     @Test(dataProvider="error")
  96     public void test_parse_error(TemporalField field, int min, int max, SignStyle style, String text, int pos, Class<?> expected) {
  97         try {
  98             getFormatter(field, min, max, style).parseUnresolved(text, new ParsePosition(pos));
  99             fail();
 100         } catch (RuntimeException ex) {
 101             assertTrue(expected.isInstance(ex));
 102         }
 103     }


 161             {2, 19, SignStyle.NEVER, 2, "1AAAAABBBBBCCCCC", 0, 0, 0},
 162         };
 163     }
 164 
 165     //-----------------------------------------------------------------------
 166     @Test(dataProvider="parseData")
 167     public void test_parse_fresh(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
 168         ParsePosition ppos = new ParsePosition(pos);
 169         DateTimeFormatter dtf = getFormatter(DAY_OF_MONTH, minWidth, maxWidth, signStyle);
 170         if (subsequentWidth > 0) {
 171             // hacky, to reserve space
 172             dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withSymbols(symbols);
 173         }
 174         TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
 175         if (ppos.getErrorIndex() != -1) {
 176             assertEquals(ppos.getErrorIndex(), expectedPos);
 177         } else {
 178             assertTrue(subsequentWidth >= 0);
 179             assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
 180             assertEquals(parsed.getLong(DAY_OF_MONTH), expectedValue);
 181             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 182             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 183         }
 184     }
 185 
 186     @Test(dataProvider="parseData")
 187     public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
 188         ParsePosition ppos = new ParsePosition(pos);
 189         DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
 190         if (subsequentWidth > 0) {
 191             // hacky, to reserve space
 192             dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withSymbols(symbols);
 193         }
 194         TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
 195         if (ppos.getErrorIndex() != -1) {
 196             assertEquals(ppos.getErrorIndex(), expectedPos);
 197         } else {
 198             assertTrue(subsequentWidth >= 0);
 199             assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
 200             assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
 201             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 202             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 203         }
 204     }
 205 
 206     //-----------------------------------------------------------------------
 207     @DataProvider(name="parseSignsStrict")
 208     Object[][] provider_parseSignsStrict() {
 209         return new Object[][] {
 210             // basics
 211             {"0", 1, 2, SignStyle.NEVER, 1, 0},
 212             {"1", 1, 2, SignStyle.NEVER, 1, 1},
 213             {"2", 1, 2, SignStyle.NEVER, 1, 2},
 214             {"3", 1, 2, SignStyle.NEVER, 1, 3},
 215             {"4", 1, 2, SignStyle.NEVER, 1, 4},
 216             {"5", 1, 2, SignStyle.NEVER, 1, 5},
 217             {"6", 1, 2, SignStyle.NEVER, 1, 6},
 218             {"7", 1, 2, SignStyle.NEVER, 1, 7},
 219             {"8", 1, 2, SignStyle.NEVER, 1, 8},
 220             {"9", 1, 2, SignStyle.NEVER, 1, 9},
 221             {"10", 1, 2, SignStyle.NEVER, 2, 10},
 222             {"100", 1, 2, SignStyle.NEVER, 2, 10},


 296             {"-50", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 297             {"-500", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 298             {"-AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 299             {"+0", 1, 2, SignStyle.EXCEEDS_PAD, 0, null},
 300             {"+5", 1, 2, SignStyle.EXCEEDS_PAD, 0, null},
 301             {"+50", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 302             {"+500", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 303             {"+AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 304        };
 305     }
 306 
 307     @Test(dataProvider="parseSignsStrict")
 308     public void test_parseSignsStrict(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 309         ParsePosition pos = new ParsePosition(0);
 310         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 311         if (pos.getErrorIndex() != -1) {
 312             assertEquals(pos.getErrorIndex(), parseLen);
 313         } else {
 314             assertEquals(pos.getIndex(), parseLen);
 315             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 316             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 317             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 318         }
 319     }
 320 
 321     //-----------------------------------------------------------------------
 322     @DataProvider(name="parseSignsLenient")
 323     Object[][] provider_parseSignsLenient() {
 324         return new Object[][] {
 325             // never
 326             {"0", 1, 2, SignStyle.NEVER, 1, 0},
 327             {"5", 1, 2, SignStyle.NEVER, 1, 5},
 328             {"50", 1, 2, SignStyle.NEVER, 2, 50},
 329             {"500", 1, 2, SignStyle.NEVER, 2, 50},
 330             {"-0", 1, 2, SignStyle.NEVER, 2, 0},
 331             {"-5", 1, 2, SignStyle.NEVER, 2, -5},
 332             {"-50", 1, 2, SignStyle.NEVER, 3, -50},
 333             {"-500", 1, 2, SignStyle.NEVER, 3, -50},
 334             {"-AAA", 1, 2, SignStyle.NEVER, 1, null},
 335             {"+0", 1, 2, SignStyle.NEVER, 2, 0},
 336             {"+5", 1, 2, SignStyle.NEVER, 2, 5},
 337             {"+50", 1, 2, SignStyle.NEVER, 3, 50},


 406             {"-500", 1, 2, SignStyle.EXCEEDS_PAD, 3, -50},
 407             {"-AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 408             {"+0", 1, 2, SignStyle.EXCEEDS_PAD, 2, 0},
 409             {"+5", 1, 2, SignStyle.EXCEEDS_PAD, 2, 5},
 410             {"+50", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 411             {"+500", 1, 2, SignStyle.EXCEEDS_PAD, 3, 50},
 412             {"+AAA", 1, 2, SignStyle.EXCEEDS_PAD, 1, null},
 413        };
 414     }
 415 
 416     @Test(dataProvider="parseSignsLenient")
 417     public void test_parseSignsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 418         setStrict(false);
 419         ParsePosition pos = new ParsePosition(0);
 420         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 421         if (pos.getErrorIndex() != -1) {
 422             assertEquals(pos.getErrorIndex(), parseLen);
 423         } else {
 424             assertEquals(pos.getIndex(), parseLen);
 425             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 426             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 427             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 428         }
 429     }
 430 
 431     //-----------------------------------------------------------------------
 432     @DataProvider(name="parseDigitsLenient")
 433     Object[][] provider_parseDigitsLenient() {
 434         return new Object[][] {
 435                 // never
 436                 {"5", 1, 2, SignStyle.NEVER, 1, 5},
 437                 {"5", 2, 2, SignStyle.NEVER, 1, 5},
 438                 {"54", 1, 3, SignStyle.NEVER, 2, 54},
 439                 {"54", 2, 3, SignStyle.NEVER, 2, 54},
 440                 {"54", 3, 3, SignStyle.NEVER, 2, 54},
 441                 {"543", 1, 3, SignStyle.NEVER, 3, 543},
 442                 {"543", 2, 3, SignStyle.NEVER, 3, 543},
 443                 {"543", 3, 3, SignStyle.NEVER, 3, 543},
 444                 {"5432", 1, 3, SignStyle.NEVER, 3, 543},
 445                 {"5432", 2, 3, SignStyle.NEVER, 3, 543},
 446                 {"5432", 3, 3, SignStyle.NEVER, 3, 543},
 447                 {"5AAA", 2, 3, SignStyle.NEVER, 1, 5},


 497                 {"543", 1, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 498                 {"543", 2, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 499                 {"543", 3, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 500                 {"5432", 1, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 501                 {"5432", 2, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 502                 {"5432", 3, 3, SignStyle.EXCEEDS_PAD, 3, 543},
 503                 {"5AAA", 2, 3, SignStyle.EXCEEDS_PAD, 1, 5},
 504         };
 505     }
 506 
 507     @Test(dataProvider="parseDigitsLenient")
 508     public void test_parseDigitsLenient(String input, int min, int max, SignStyle style, int parseLen, Integer parseVal) throws Exception {
 509         setStrict(false);
 510         ParsePosition pos = new ParsePosition(0);
 511         TemporalAccessor parsed = getFormatter(DAY_OF_MONTH, min, max, style).parseUnresolved(input, pos);
 512         if (pos.getErrorIndex() != -1) {
 513             assertEquals(pos.getErrorIndex(), parseLen);
 514         } else {
 515             assertEquals(pos.getIndex(), parseLen);
 516             assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
 517             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 518             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 519         }
 520     }
 521 
 522     //-----------------------------------------------------------------------
 523     @DataProvider(name="parseDigitsAdjacentLenient")
 524     Object[][] provider_parseDigitsAdjacentLenient() {
 525         return new Object[][] {
 526                 // never
 527                 {"5", 1, null, null},
 528                 {"54", 1, null, null},
 529 
 530                 {"543", 3, 5, 43},
 531                 {"543A", 3, 5, 43},
 532 
 533                 {"5432", 4, 54, 32},
 534                 {"5432A", 4, 54, 32},
 535 
 536                 {"54321", 4, 54, 32},
 537                 {"54321A", 4, 54, 32},
 538         };
 539     }
 540 
 541     @Test(dataProvider="parseDigitsAdjacentLenient")
 542     public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
 543         setStrict(false);
 544         ParsePosition pos = new ParsePosition(0);
 545         DateTimeFormatter f = builder
 546                 .appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
 547                 .appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withSymbols(symbols);
 548         TemporalAccessor parsed = f.parseUnresolved(input, pos);
 549         if (pos.getErrorIndex() != -1) {
 550             assertEquals(pos.getErrorIndex(), parseLen);
 551         } else {
 552             assertEquals(pos.getIndex(), parseLen);
 553             assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
 554             assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
 555             assertEquals(parsed.query(TemporalQuery.chronology()), null);
 556             assertEquals(parsed.query(TemporalQuery.zoneId()), null);
 557         }
 558     }
 559 
 560 }