From 2b84af2cf1119df8c8e233e2fa55c047a1a2f9c2 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Sat, 23 Jul 2022 00:43:44 +0200 Subject: [PATCH] tests: updated to use latest lexer API lexer_test.cpp: * Tests fail to pass, but code now compiles after being adjusted to use latest API for lexer datatype. --- tests/compiler/lexer_test.cpp | 64 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/tests/compiler/lexer_test.cpp b/tests/compiler/lexer_test.cpp index 1a2324de..655ed5f8 100644 --- a/tests/compiler/lexer_test.cpp +++ b/tests/compiler/lexer_test.cpp @@ -7,51 +7,53 @@ TEST_CASE("Tokenize basic primitives") { std::vector res; - res = lexer("69420", ""); + res = LEXER("69420", "").result(); CHECK(res[0].tkType == tk_integer); CHECK(res[0].keyword == "69420"); - res = lexer("5.32006", ""); + res = LEXER("5.32006", "").result(); CHECK(res[0].tkType == tk_decimal); CHECK(res[0].keyword == "5.32006"); - res = lexer("\"A blazing fast language\"", ""); + res = LEXER("\"A blazing fast language\"", "").result(); CHECK(res[0].tkType == tk_string); CHECK(res[0].keyword == std::string("A blazing fast language")); - res = lexer("True", ""); + res = LEXER("True", "").result(); CHECK(res[0].tkType == tk_true); } TEST_CASE("Tokenize variable declarations") { - std::vector res = lexer("int test = 23", ""); - - REQUIRE(res.size() == 5); - - CHECK(res[0].tkType == tk_identifier); - CHECK(res[1].tkType == tk_identifier); - CHECK(res[2].tkType == tk_assign); - CHECK(res[3].tkType == tk_integer); - CHECK(res[4].tkType == tk_eof); -} - -TEST_CASE("Tokenize if-else statements") { - std::vector res = lexer("if test:\n print(\"true!\")\nelse:\n print(\"false!\")", ""); + std::vector res = LEXER("int test = 23", "").result(); - REQUIRE(res.size() == 18); + REQUIRE(res.size() == 5); - SUBCASE("Emit ident and dedent tokens") { - CHECK(res[3].tkType == tk_ident); - CHECK(res[8].tkType == tk_dedent); - CHECK(res[11].tkType == tk_ident); - CHECK(res[16].tkType == tk_dedent); - } - - SUBCASE("Emit if and else tokens") { - CHECK(res[0].tkType == tk_if); - CHECK(res[2].tkType == tk_colon); + CHECK(res[0].tkType == tk_identifier); + CHECK(res[1].tkType == tk_identifier); + CHECK(res[2].tkType == tk_assign); + CHECK(res[3].tkType == tk_integer); + CHECK(res[4].tkType == tk_eof); +} - CHECK(res[9].tkType == tk_else); - CHECK(res[10].tkType == tk_colon); - } +TEST_CASE("Tokenize if-else statements") { + std::vector res = + LEXER("if test:\n print(\"true!\")\nelse:\n print(\"false!\")", "") + .result(); + + REQUIRE(res.size() == 18); + + SUBCASE("Emit ident and dedent tokens") { + CHECK(res[3].tkType == tk_ident); + CHECK(res[8].tkType == tk_dedent); + CHECK(res[11].tkType == tk_ident); + CHECK(res[16].tkType == tk_dedent); + } + + SUBCASE("Emit if and else tokens") { + CHECK(res[0].tkType == tk_if); + CHECK(res[2].tkType == tk_colon); + + CHECK(res[9].tkType == tk_else); + CHECK(res[10].tkType == tk_colon); + } }