diff --git a/tests/test_ASTNodeIncDecExpressionBuilder.cpp b/tests/test_ASTNodeIncDecExpressionBuilder.cpp index 11e270b867d1afe327a178a9f057293ddd17e7e4..2a05900e8db3c832a5e9aee2659a29997c00e725 100644 --- a/tests/test_ASTNodeIncDecExpressionBuilder.cpp +++ b/tests/test_ASTNodeIncDecExpressionBuilder.cpp @@ -44,6 +44,25 @@ REQUIRE(ast_output.str() == expected_output); \ } +#define DISALLOWED_CHAINED_AST(data, expected_error) \ + { \ + static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ + static_assert(std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view> or \ + std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>); \ + \ + string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + ASTNodeValueBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeTypeCleaner<language::declaration>{*ast}; \ + \ + REQUIRE_THROWS_WITH(ASTNodeExpressionBuilder{*ast}, expected_error); \ + } + TEST_CASE("ASTNodeIncDecExpressionBuilder", "[language]") { SECTION("Pre-increment") @@ -317,5 +336,140 @@ x--; REQUIRE_THROWS_WITH(ASTNodeIncDecExpressionBuilder{*ast}, "unexpected error: undefined data type for unary operator"); } + + SECTION("Not allowed chained ++/--") + { + SECTION("++ ++ a") + { + std::string_view data = R"( +1 ++ ++; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("++ -- a") + { + std::string_view data = R"( +1 ++ --; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("-- ++ a") + { + std::string_view data = R"( +1 -- ++; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("-- -- a") + { + std::string_view data = R"( +1 -- --; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("a ++ ++") + { + std::string_view data = R"( +++ ++ 1; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("a ++ --") + { + std::string_view data = R"( +++ -- 1; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("a -- ++") + { + std::string_view data = R"( +-- ++ 1; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("a -- --") + { + std::string_view data = R"( +-- -- 1; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("++ a ++") + { + std::string_view data = R"( +++ 1 ++; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("++ a --") + { + std::string_view data = R"( +++ 1 --; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("-- a ++") + { + std::string_view data = R"( +-- 1 ++; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + + SECTION("-- --") + { + std::string_view data = R"( +-- 1 --; +)"; + + std::string error_message = R"(chaining ++ or -- operators is not allowed)"; + + DISALLOWED_CHAINED_AST(data, error_message) + } + } } }