Fixed: [Issue 153] '-inf' is not supported as default value of double or
float options.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue153_AddSupportForNegativeInf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue153_AddSupportForNegativeInf_Test.java
new file mode 100644
index 0000000..17553e1
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue153_AddSupportForNegativeInf_Test.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.bugs;
+
+import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
+import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+
+import org.junit.*;
+
+/**
+ * Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=153">Issue 153</a>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Issue153_AddSupportForNegativeInf_Test {
+
+ @Rule public XtextRule xtext = createWith(unitTestSetup());
+
+ // message Foo {
+ // optional double bar = 1 [default = -inf];
+ // }
+ @Test public void should_recognize_negative_inf() {
+ assertNotNull(xtext.root());
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter_toValue_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter_toValue_Test.java
index 1daa3f7..d0411c0 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter_toValue_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter_toValue_Test.java
@@ -49,7 +49,8 @@
{ "-3.1", -3.1D },
{ ".3", 0.3D },
{ "nan", NaN },
- { "inf", POSITIVE_INFINITY }
+ { "inf", POSITIVE_INFINITY },
+ { "-inf", NEGATIVE_INFINITY }
});
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index 0b45c43..69ec1ee 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -134,7 +134,7 @@
double=DOUBLE;
terminal DOUBLE returns ecore::EDouble:
- (('-')? (NUMBER)* ('.' (NUMBER)+)? (('e'|'E')('-')? (NUMBER)+)?) | 'nan' | 'inf';
+ (('-')? (NUMBER)* ('.' (NUMBER)+)? (('e'|'E')('-')? (NUMBER)+)?) | 'nan' | 'inf' | '-inf';
StringRef:
string=STRING;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
index 6c9fdeb..9a4086c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
@@ -35,6 +35,7 @@
if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to double.", node, null);
if ("nan".equals(string)) return NaN;
if ("inf".equals(string)) return POSITIVE_INFINITY;
+ if ("-inf".equals(string)) return NEGATIVE_INFINITY;
try {
return Double.parseDouble(string);
} catch (NumberFormatException e) {