|
@@ -89,6 +89,13 @@ public class IntervalsTests extends ESTestCase {
|
|
|
assertEquals(maybeNegate(sign, Duration.ofSeconds(randomSeconds).plusMillis(randomMillis)), amount);
|
|
|
}
|
|
|
|
|
|
+ public void testSecondNoMillisInterval() throws Exception {
|
|
|
+ int randomSeconds = randomNonNegativeInt();
|
|
|
+ String value = format(Locale.ROOT, "%s%d", sign, randomSeconds);
|
|
|
+ TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_SECOND);
|
|
|
+ assertEquals(maybeNegate(sign, Duration.ofSeconds(randomSeconds)), amount);
|
|
|
+ }
|
|
|
+
|
|
|
public void testYearToMonth() throws Exception {
|
|
|
int randomYear = randomNonNegativeInt();
|
|
|
int randomMonth = randomInt(11);
|
|
@@ -119,9 +126,12 @@ public class IntervalsTests extends ESTestCase {
|
|
|
int randomHour = randomInt(23);
|
|
|
int randomMinute = randomInt(59);
|
|
|
int randomSecond = randomInt(59);
|
|
|
- int randomMilli = randomInt(999999999);
|
|
|
|
|
|
- String value = format(Locale.ROOT, "%s%d %d:%d:%d.%d", sign, randomDay, randomHour, randomMinute, randomSecond, randomMilli);
|
|
|
+ boolean withMillis = randomBoolean();
|
|
|
+ int randomMilli = withMillis ? randomInt(999999999) : 0;
|
|
|
+ String millisString = withMillis ? "." + randomMilli : "";
|
|
|
+
|
|
|
+ String value = format(Locale.ROOT, "%s%d %d:%d:%d%s", sign, randomDay, randomHour, randomMinute, randomSecond, millisString);
|
|
|
TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_DAY_TO_SECOND);
|
|
|
assertEquals(maybeNegate(sign, Duration.ofDays(randomDay).plusHours(randomHour).plusMinutes(randomMinute)
|
|
|
.plusSeconds(randomSecond).plusMillis(randomMilli)), amount);
|
|
@@ -139,9 +149,12 @@ public class IntervalsTests extends ESTestCase {
|
|
|
int randomHour = randomNonNegativeInt();
|
|
|
int randomMinute = randomInt(59);
|
|
|
int randomSecond = randomInt(59);
|
|
|
- int randomMilli = randomInt(999999999);
|
|
|
|
|
|
- String value = format(Locale.ROOT, "%s%d:%d:%d.%d", sign, randomHour, randomMinute, randomSecond, randomMilli);
|
|
|
+ boolean withMillis = randomBoolean();
|
|
|
+ int randomMilli = withMillis ? randomInt(999999999) : 0;
|
|
|
+ String millisString = withMillis ? "." + randomMilli : "";
|
|
|
+
|
|
|
+ String value = format(Locale.ROOT, "%s%d:%d:%d%s", sign, randomHour, randomMinute, randomSecond, millisString);
|
|
|
TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_HOUR_TO_SECOND);
|
|
|
assertEquals(maybeNegate(sign,
|
|
|
Duration.ofHours(randomHour).plusMinutes(randomMinute).plusSeconds(randomSecond).plusMillis(randomMilli)), amount);
|
|
@@ -150,9 +163,12 @@ public class IntervalsTests extends ESTestCase {
|
|
|
public void testMinuteToSecond() throws Exception {
|
|
|
int randomMinute = randomNonNegativeInt();
|
|
|
int randomSecond = randomInt(59);
|
|
|
- int randomMilli = randomInt(999999999);
|
|
|
|
|
|
- String value = format(Locale.ROOT, "%s%d:%d.%d", sign, randomMinute, randomSecond, randomMilli);
|
|
|
+ boolean withMillis = randomBoolean();
|
|
|
+ int randomMilli = withMillis ? randomInt(999999999) : 0;
|
|
|
+ String millisString = withMillis ? "." + randomMilli : "";
|
|
|
+
|
|
|
+ String value = format(Locale.ROOT, "%s%d:%d%s", sign, randomMinute, randomSecond, millisString);
|
|
|
TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_MINUTE_TO_SECOND);
|
|
|
assertEquals(maybeNegate(sign, Duration.ofMinutes(randomMinute).plusSeconds(randomSecond).plusMillis(randomMilli)), amount);
|
|
|
}
|
|
@@ -187,6 +203,20 @@ public class IntervalsTests extends ESTestCase {
|
|
|
+ "], expected a positive number up to [23]", pe.getMessage());
|
|
|
}
|
|
|
|
|
|
+ public void testIncompleteYearToMonthInterval() throws Exception {
|
|
|
+ String value = "123-";
|
|
|
+ ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_YEAR_TO_MONTH));
|
|
|
+ assertEquals("line -1:0: Invalid [INTERVAL YEAR TO MONTH] value [123-]: incorrect format, expecting [numeric]-[numeric]",
|
|
|
+ pe.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testIncompleteDayToHourInterval() throws Exception {
|
|
|
+ String value = "123 23:";
|
|
|
+ ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_DAY_TO_HOUR));
|
|
|
+ assertEquals("line -1:0: Invalid [INTERVAL DAY TO HOUR] value [123 23:]: unexpected trailing characters found [:]",
|
|
|
+ pe.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
public void testExtraCharLeading() throws Exception {
|
|
|
String value = "a123";
|
|
|
ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_YEAR));
|