Skip to content
Snippets Groups Projects
Commit 03e27112 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add tests for disallowed ++/-- chains

parent c6b340a8
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -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)
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment