Added support for negative numbers

This commit is contained in:
moandji.ezana 2013-03-22 14:36:48 +02:00
parent 2483dc48ae
commit 4473418a72
2 changed files with 15 additions and 1 deletions

View file

@ -77,7 +77,7 @@ class TomlParser extends BaseParser<Object> {
}
Rule NumberValue() {
return Sequence(OneOrMore(FirstOf(Digit(), '.')), pushNumber(match()));
return Sequence(Sequence(Optional('-'), OneOrMore(FirstOf(Digit(), '.'))), pushNumber(match()));
}
Rule StringValue() {

View file

@ -29,6 +29,13 @@ public class TomlTest {
assertEquals(1001, toml.getLong("b").intValue());
}
@Test
public void should_get_negative_number() throws Exception {
Toml toml = new Toml().parse("b = -1001");
assertEquals(-1001, toml.getLong("b").intValue());
}
@Test
public void should_get_list() throws Exception {
Toml toml = new Toml().parse("list = [\"a\", \"b\", \"c\"]");
@ -63,6 +70,13 @@ public class TomlTest {
assertEquals(5.25D, toml.getDouble("double").doubleValue(), 0.0);
}
@Test
public void should_get_negative_double() throws Exception {
Toml toml = new Toml().parse("double = -5.25");
assertEquals(-5.25D, toml.getDouble("double").doubleValue(), 0.0);
}
@Test
public void should_get_key_group() throws Exception {
Toml toml = new Toml().parse("[group]\nkey = \"value\"");