diff --git a/src/main/java/com/google/api/generator/engine/lexicon/Literal.java b/src/main/java/com/google/api/generator/engine/lexicon/Literal.java index fb97f9fd0f..8ffd5ea989 100644 --- a/src/main/java/com/google/api/generator/engine/lexicon/Literal.java +++ b/src/main/java/com/google/api/generator/engine/lexicon/Literal.java @@ -22,13 +22,14 @@ public class Literal { private static final String BOOLEAN_FALSE = "false"; private static final String NULL_VALUE = "null"; - private static final Pattern INTEGER_PATTERN = Pattern.compile("^[0-9]+$"); - private static final Pattern LONG_PATTERN = Pattern.compile("^[0-9]+[Ll]?$"); + private static final Pattern INTEGER_PATTERN = Pattern.compile("^\\-?[0-9]+$"); + private static final Pattern LONG_PATTERN = Pattern.compile("^\\-?[0-9]+[Ll]?$"); private static final Pattern FLOAT_PATTERN = - Pattern.compile("^[0-9]+([fF]|(\\.(([0-9]+[fF])|[fF])))?$"); + Pattern.compile("^\\-?[0-9]+([fF]|(\\.(([0-9]+[fF])|[fF])))?$"); private static final Pattern DOUBLE_PATTERN_ONE = - Pattern.compile("^[0-9]+(\\.[0-9]+)?(\\.?[eE]\\-?[0-9]+)$"); - private static final Pattern DOUBLE_PATTERN_TWO = Pattern.compile("^\\d*\\.\\d+$|^\\d+\\.\\d*$"); + Pattern.compile("^\\-?[0-9]+(\\.[0-9]+)?(\\.?[eE]\\-?[0-9]+)$"); + private static final Pattern DOUBLE_PATTERN_TWO = + Pattern.compile("^\\-?\\d*\\.\\d+$|^\\d+\\.\\d*$"); public static boolean isBooleanLiteral(String str) { return str.equals(BOOLEAN_TRUE) || str.equals(BOOLEAN_FALSE); diff --git a/src/test/java/com/google/api/generator/engine/lexicon/LiteralTest.java b/src/test/java/com/google/api/generator/engine/lexicon/LiteralTest.java index ac22cbde6e..80b155045e 100644 --- a/src/test/java/com/google/api/generator/engine/lexicon/LiteralTest.java +++ b/src/test/java/com/google/api/generator/engine/lexicon/LiteralTest.java @@ -37,6 +37,7 @@ public void nullLDetected() { public void integerDetected() { assertThat(Literal.isIntegerLiteral("a123")).isFalse(); assertThat(Literal.isIntegerLiteral("123")).isTrue(); + assertThat(Literal.isIntegerLiteral("-123")).isTrue(); assertThat(Literal.isIntegerLiteral("123L")).isFalse(); assertThat(Literal.isIntegerLiteral("123r")).isFalse(); assertThat(Literal.isIntegerLiteral("123e2")).isFalse(); @@ -47,6 +48,7 @@ public void longDetected() { assertThat(Literal.isLongLiteral("123")).isTrue(); assertThat(Literal.isLongLiteral("123L")).isTrue(); assertThat(Literal.isLongLiteral("123l")).isTrue(); + assertThat(Literal.isLongLiteral("-123l")).isTrue(); assertThat(Literal.isLongLiteral("123e")).isFalse(); } @@ -58,6 +60,7 @@ public void floatDetected() { assertThat(Literal.isFloatLiteral("0.01")).isFalse(); assertThat(Literal.isFloatLiteral(".01")).isFalse(); assertThat(Literal.isFloatLiteral("123.f")).isTrue(); + assertThat(Literal.isFloatLiteral("-123.f")).isTrue(); assertThat(Literal.isFloatLiteral("123.F")).isTrue(); assertThat(Literal.isFloatLiteral("123.234F")).isTrue(); assertThat(Literal.isFloatLiteral("123.234Fe-3")).isFalse(); @@ -69,11 +72,14 @@ public void doubleDetected() { assertThat(Literal.isDoubleLiteral("123")).isTrue(); assertThat(Literal.isDoubleLiteral("0.01")).isTrue(); assertThat(Literal.isDoubleLiteral(".01")).isTrue(); + assertThat(Literal.isDoubleLiteral("-.01")).isTrue(); assertThat(Literal.isDoubleLiteral("123.0")).isTrue(); + assertThat(Literal.isDoubleLiteral("-123.0")).isTrue(); assertThat(Literal.isDoubleLiteral("123f")).isTrue(); assertThat(Literal.isDoubleLiteral("123E-2")).isTrue(); assertThat(Literal.isDoubleLiteral("123.134E-2")).isTrue(); assertThat(Literal.isDoubleLiteral("123.E-2")).isTrue(); + assertThat(Literal.isDoubleLiteral("-123.E-2")).isTrue(); assertThat(Literal.isDoubleLiteral("123e2")).isTrue(); assertThat(Literal.isDoubleLiteral("123e")).isFalse(); assertThat(Literal.isDoubleLiteral("123E-")).isFalse();