diff options
| author | Elias Haugsbakk <[email protected]> | 2026-09-21 14:36:59 +0200 |
|---|---|---|
| committer | Elias Haugsbakk <[email protected]> | 2026-09-21 14:36:59 +0200 |
| commit | e7720e2d9e1319712f85cb0527e17f1251bd7d2c (patch) | |
| tree | 19cb8b0f49a0fe234fc0c0bfb41dc5c520b1630b /src/test/java/no/eliashaugsbakk/kompilator/parsing | |
| parent | 84215a9b8f79035ebec83fe38bc696b5ae78de5d (diff) | |
add position info to semantic and IRgen exceptions
Diffstat (limited to 'src/test/java/no/eliashaugsbakk/kompilator/parsing')
| -rw-r--r-- | src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java b/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java index 0de2b5f..e4d48ec 100644 --- a/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java +++ b/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java @@ -12,6 +12,7 @@ import no.eliashaugsbakk.kompilator.parsing.node.Program; import no.eliashaugsbakk.kompilator.parsing.node.expression.FunctionCall; import no.eliashaugsbakk.kompilator.parsing.node.expression.literal.StringLiteral; import no.eliashaugsbakk.kompilator.parsing.node.statement.ExpressionStatement; +import no.eliashaugsbakk.kompilator.tokenization.Position; import no.eliashaugsbakk.kompilator.tokenization.Token; import org.junit.jupiter.api.Test; @@ -20,11 +21,11 @@ class ParserTest { @Test void validSyntaxBuildsCorrectTree() throws ParserException { List<Token> tokens = List.of( - new Token(KEYWORD, "skriv", 1, 0), - new Token(LPAREN, "(", 1, 5), - new Token(STRING_LITERAL, "Hello", 1, 6), - new Token(RPAREN, ")", 1, 13), - new Token(SEMICOLON, ";", 1, 14) + new Token(KEYWORD, "skriv", new Position(1, 0)), + new Token(LPAREN, "(", new Position(1, 5)), + new Token(STRING_LITERAL, "Hello", new Position(1, 6)), + new Token(RPAREN, ")", new Position(1, 13)), + new Token(SEMICOLON, ";", new Position(1, 14)) ); AST ast = new Parser(tokens).parse(); @@ -47,10 +48,10 @@ class ParserTest { @Test void missingSemicolonThrows() { List<Token> tokens = List.of( - new Token(KEYWORD, "print", 1, 0), - new Token(LPAREN, "(", 1, 5), - new Token(STRING_LITERAL, "Hello", 1, 6), - new Token(RPAREN, ")", 1, 13) + new Token(KEYWORD, "print", new Position(1, 0)), + new Token(LPAREN, "(", new Position(1, 5)), + new Token(STRING_LITERAL, "Hello", new Position(1, 6)), + new Token(RPAREN, ")", new Position(1, 13)) ); assertThrows(ParserException.class, () -> new Parser(tokens).parse()); @@ -59,10 +60,10 @@ class ParserTest { @Test void missingParenthesisThrows() { List<Token> tokens = List.of( - new Token(KEYWORD, "print", 1, 0), - new Token(STRING_LITERAL, "Hello", 1, 5), - new Token(RPAREN, ")", 1, 12), - new Token(SEMICOLON, ";", 1, 13) + new Token(KEYWORD, "print", new Position(1, 0)), + new Token(STRING_LITERAL, "Hello", new Position(1, 5)), + new Token(RPAREN, ")", new Position(1, 12)), + new Token(SEMICOLON, ";", new Position(1, 13)) ); assertThrows(ParserException.class, () -> new Parser(tokens).parse()); |
