From 370e147a121a57ec9e14542a443ab96e3573d5d3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 5 Jul 2023 21:15:51 +0100 Subject: Parse negative ints --- .../compiler/parser/ParserIntLiteralTests.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/parser/ParserIntLiteralTests.java b/src/test/java/org/shedlang/compiler/parser/ParserIntLiteralTests.java index 61908772..bc0dcad9 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserIntLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserIntLiteralTests.java @@ -7,7 +7,7 @@ import static org.shedlang.compiler.parser.ParserTesting.parseString; import static org.zwobble.precisely.AssertThat.assertThat; public class ParserIntLiteralTests { - // TODO: negatives + // TODO: forbid negative zero? // TODO: forbid leading zeroes? @Test @@ -36,4 +36,22 @@ public class ParserIntLiteralTests { assertThat(node, isUntypedIntLiteralNode(723)); } + + @Test + public void canParseSingleDigitNegativeInt() { + var source = "-7"; + + var node = parseString(source, Parser::parseTopLevelExpression); + + assertThat(node, isUntypedIntLiteralNode(-7)); + } + + @Test + public void canParseManyDigitNegativeInt() { + var source = "-723"; + + var node = parseString(source, Parser::parseTopLevelExpression); + + assertThat(node, isUntypedIntLiteralNode(-723)); + } } -- cgit v1.2.3