From e2e0ed950bb147ebca3b9ac879268feeb185e20b Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Wed, 3 May 2023 23:17:50 -0300 Subject: parser: Introduce statement keywords This commit introduces a few changes in pipalang syntax. Now, both functions and variables requires keywords to be defined. before: main(): i32 { a: i32 = 2; return a; } now: fn main(): i32 { let a: i32 = 2; return a; } Signed-off-by: Carlos Maniero Reviewed-by: Johnny Richard --- test/lexer_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/lexer_test.c') diff --git a/test/lexer_test.c b/test/lexer_test.c index 5326f5c..a3f644d 100644 --- a/test/lexer_test.c +++ b/test/lexer_test.c @@ -51,6 +51,22 @@ assert_token_at(char *source, int token_index, token_kind_t expected_kind, char assert_string_equal(expected, actual); } +void +assert_keyword(char *source, token_kind_t expected_kind) +{ + assert_token_at(source, 0, expected_kind, source); +} + +static MunitResult +test_tokenize_keywords(const MunitParameter params[], void *user_data_or_fixture) +{ + assert_keyword("return", TOKEN_KEYWORD_RETURN); + assert_keyword("fn", TOKEN_KEYWORD_FN); + assert_keyword("let", TOKEN_KEYWORD_LET); + + return MUNIT_OK; +} + static MunitResult test_tokenize_number(const MunitParameter params[], void *user_data_or_fixture) { @@ -106,6 +122,7 @@ test_peek_next_token(const MunitParameter params[], void *user_data_or_fixture) static MunitTest tests[] = { { "/test_tokenize_digit", test_tokenize_number, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { "/test_tokenize_keywords", test_tokenize_keywords, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_tokenize_op", test_tokenize_op, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_tokenize_unknown", test_tokenize_unknown, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_peek_next_token", test_peek_next_token, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, -- cgit v1.2.3