From 767a2ebcb10f5f112763abd7e3063c62a29d8cc6 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Tue, 15 Jul 2025 00:05:48 +0200 Subject: [PATCH] added tests for malformed if to check of memory leaks --- test/parser/if.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/parser/if.cpp b/test/parser/if.cpp index c98b353..a64f822 100644 --- a/test/parser/if.cpp +++ b/test/parser/if.cpp @@ -7,7 +7,43 @@ #include TEST_SUITE("Parser: if") { - TEST_CASE("Malformed if then else (checking for memory leaks)") {} + TEST_CASE("Malformed if then else (checking for memory leaks)") { + SUBCASE("Missing open paren") { + test_failing_parsing( + "if x > 15) {\ + return x;\ + }", + {token::type::LPAREN} + ); + } + + SUBCASE("Missing closing paren") { + test_failing_parsing( + "if (x > 15 {\ + return x;\ + }", + {token::type::RPAREN} + ); + } + + SUBCASE("Missing opening brace") { + test_failing_parsing( + "if (x > 15) \ + return x;\ + }", + {token::type::LBRACE} + ); + } + + SUBCASE("Missing closing brace") { + test_failing_parsing( + "if (x > 15) { \ + return x;\ + ", + {token::type::RBRACE} + ); + } + } TEST_CASE_FIXTURE(ParserFixture, "Parse well formed simple if ") { setup("\