using test suites

This commit is contained in:
Karma Riuk
2025-07-08 10:36:08 +02:00
parent ef624de4ef
commit 2dfff61346
3 changed files with 192 additions and 186 deletions

View File

@@ -6,7 +6,8 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
TEST_CASE("Single character token") { TEST_SUITE("Lexer") {
TEST_CASE("Single character token") {
struct test { struct test {
token::type expectedType; token::type expectedType;
std::string expectedLiteral; std::string expectedLiteral;
@@ -34,9 +35,9 @@ TEST_CASE("Single character token") {
REQUIRE(tok.type == t.expectedType); REQUIRE(tok.type == t.expectedType);
REQUIRE(tok.literal == t.expectedLiteral); REQUIRE(tok.literal == t.expectedLiteral);
} }
}; };
TEST_CASE("More tokens") { TEST_CASE("More tokens") {
struct test { struct test {
token::type expectedType; token::type expectedType;
std::string expectedLiteral; std::string expectedLiteral;
@@ -158,4 +159,5 @@ if (5 < 10) {\
REQUIRE(tok.type == t.expectedType); REQUIRE(tok.type == t.expectedType);
REQUIRE(tok.literal == t.expectedLiteral); REQUIRE(tok.literal == t.expectedLiteral);
} }
}; };
}

View File

@@ -57,7 +57,8 @@ void test_failing_let_parsing(
delete program; delete program;
} }
TEST_CASE("Malformed let statement (checking for memory leaks)") { TEST_SUITE("Parser: let") {
TEST_CASE("Malformed let statement (checking for memory leaks)") {
SUBCASE("Second token not identifier") { SUBCASE("Second token not identifier") {
test_failing_let_parsing("let 5 = 5;", {token::type::IDENTIFIER}); test_failing_let_parsing("let 5 = 5;", {token::type::IDENTIFIER});
} }
@@ -80,9 +81,9 @@ TEST_CASE("Malformed let statement (checking for memory leaks)") {
1 1
); );
} }
} }
TEST_CASE("Parse let statement") { TEST_CASE("Parse well formed let statements") {
std::stringstream input("\ std::stringstream input("\
let x = 5;\ let x = 5;\
let y = 10;\ let y = 10;\
@@ -119,4 +120,5 @@ let foobar = 103213;\
} }
delete program; delete program;
}
} }

View File

@@ -6,7 +6,8 @@
#include <doctest.h> #include <doctest.h>
#include <sstream> #include <sstream>
TEST_CASE("Parse return statement") { TEST_SUITE("Parser: return") {
TEST_CASE("Parse return statement") {
std::stringstream input("\ std::stringstream input("\
return 5;\ return 5;\
return 10;\ return 10;\
@@ -36,4 +37,5 @@ return 103213;\
} }
delete program; delete program;
}
} }