Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #128 from tcoyvwac/fix/update-to-latest-lexer-api-…
Browse files Browse the repository at this point in the history
…tests

tests: Updated to use latest `lexer` API
  • Loading branch information
SaptakBhoumik authored Jul 23, 2022
2 parents 193179c + 2b84af2 commit c349cce
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions tests/compiler/lexer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,53 @@
TEST_CASE("Tokenize basic primitives") {
std::vector<Token> 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<Token> 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<Token> res = lexer("if test:\n print(\"true!\")\nelse:\n print(\"false!\")", "");
std::vector<Token> 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<Token> 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);
}
}

0 comments on commit c349cce

Please sign in to comment.