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

Add missing ListAffectationProcessor tests

Mainly test that subscript values can be affected in lists such as
``
R^3 x;
(x[1], x[0], x[2]) = (1, 2, 3);
``
then `x` contains `(2, 1, 3)`
parent 82ec5279
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -413,8 +413,10 @@ class ListAffectationProcessor final : public INodeProcessor ...@@ -413,8 +413,10 @@ class ListAffectationProcessor final : public INodeProcessor
DataVariant& value = i_symbol->attributes().value(); DataVariant& value = i_symbol->attributes().value();
if (array_expression.m_data_type != ASTNodeDataType::vector_t) { if (array_expression.m_data_type != ASTNodeDataType::vector_t) {
// LCOV_EXCL_START
throw parse_error("unexpected error: invalid lhs (expecting R^d)", throw parse_error("unexpected error: invalid lhs (expecting R^d)",
std::vector{array_subscript_expression.begin()}); std::vector{array_subscript_expression.begin()});
// LCOV_EXCL_STOP
} }
auto& index_expression = *array_subscript_expression.children[1]; auto& index_expression = *array_subscript_expression.children[1];
...@@ -450,13 +452,17 @@ class ListAffectationProcessor final : public INodeProcessor ...@@ -450,13 +452,17 @@ class ListAffectationProcessor final : public INodeProcessor
std::make_unique<AffectationExecutorT>(lhs_node, std::get<ArrayTypeT>(value), index_expression)); std::make_unique<AffectationExecutorT>(lhs_node, std::get<ArrayTypeT>(value), index_expression));
break; break;
} }
// LCOV_EXCL_START
default: { default: {
throw parse_error("unexpected error: invalid vector dimension", throw parse_error("unexpected error: invalid vector dimension",
std::vector{array_subscript_expression.begin()}); std::vector{array_subscript_expression.begin()});
} }
// LCOV_EXCL_STOP
} }
} else { } else {
// LCOV_EXCL_START
throw parse_error("unexpected error: invalid left hand side", std::vector{lhs_node.begin()}); throw parse_error("unexpected error: invalid left hand side", std::vector{lhs_node.begin()});
// LCOV_EXCL_STOP
} }
} }
......
...@@ -107,5 +107,12 @@ TEST_CASE("ListAffectationProcessor", "[language]") ...@@ -107,5 +107,12 @@ TEST_CASE("ListAffectationProcessor", "[language]")
CHECK_AFFECTATION_RESULT(R"(R^3 v = (1,2,3); R*R^2*string (x,u,s) = (1.2, (2,3), v);)", "s", os.str()); CHECK_AFFECTATION_RESULT(R"(R^3 v = (1,2,3); R*R^2*string (x,u,s) = (1.2, (2,3), v);)", "s", os.str());
} }
} }
SECTION("compound with subscript values")
{
CHECK_AFFECTATION_RESULT(R"(R^3 x; (x[0], x[2], x[1]) = (4, 6, 5);)", "x", (TinyVector<3>{4, 5, 6}));
CHECK_AFFECTATION_RESULT(R"(R^2 x; (x[1], x[0]) = (3, 6);)", "x", (TinyVector<2>{6, 3}));
CHECK_AFFECTATION_RESULT(R"(R^1 x; R y; (y, x[0]) = (4, 2.3);)", "x", (TinyVector<1>{2.3}));
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment