From 453c72af6d2b225bea7d101618e196c1e23e6650 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 18 May 2026 13:11:00 +0200 Subject: [PATCH] tests(parser): add basic lexer test add a basic test for the annotation lexer to check punctuation tokens --- tests/lexer/test_annotation_lexer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/lexer/test_annotation_lexer.py diff --git a/tests/lexer/test_annotation_lexer.py b/tests/lexer/test_annotation_lexer.py new file mode 100644 index 0000000..4d08f7f --- /dev/null +++ b/tests/lexer/test_annotation_lexer.py @@ -0,0 +1,26 @@ +import pytest + +from lexer.annotations import AnnotationLexer +from lexer.token import Token, TokenType + + +def scan(source: str) -> list[Token]: + return AnnotationLexer(source).process() + +def assert_n_tokens(tokens: list[Token], n: int): + assert len(tokens) == n + 1 + assert tokens[-1].type == TokenType.EOF + +@pytest.mark.parametrize("src,expected", [ + ("(", TokenType.LEFT_PAREN), + (")", TokenType.RIGHT_PAREN), + ("[", TokenType.LEFT_BRACKET), + ("]", TokenType.RIGHT_BRACKET), + (":", TokenType.COLON), + (",", TokenType.COMMA), + ("_", TokenType.UNDERSCORE), +]) +def test_punctuation(src: str, expected: TokenType): + tokens: list[Token] = scan(src) + assert_n_tokens(tokens, 1) + assert tokens[0].type == expected \ No newline at end of file