diff --git a/tests/test_ASTNodeFunctionExpressionBuilder.cpp b/tests/test_ASTNodeFunctionExpressionBuilder.cpp index a8c2e0f15525c78dfd9e35df0672761d3df3b1f0..d10d243a8de7b16b3b6c33bc81d55343b2298953 100644 --- a/tests/test_ASTNodeFunctionExpressionBuilder.cpp +++ b/tests/test_ASTNodeFunctionExpressionBuilder.cpp @@ -1141,5 +1141,98 @@ f((1,2,3),2,3); CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{"bad number of arguments: expecting 2, provided 3"}); } } + + SECTION("non pure function") + { + SECTION("argument modification") + { + SECTION("++ argument") + { + std::string_view data = R"( +let non_pure : R -> R, x -> 3 * ++x; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("argument ++") + { + std::string_view data = R"( +let non_pure : R -> R, x -> 1 + x ++; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("-- argument") + { + std::string_view data = R"( +let non_pure : R -> R, x -> 3 * --x; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("argument --") + { + std::string_view data = R"( +let non_pure : R -> R, x -> 1 + x --; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + } + + SECTION("outer variable modification") + { + SECTION("++ outer variable") + { + std::string_view data = R"( +let a:R, a = 4; +let non_pure : R -> R, x -> x * ++a; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("outer variable ++") + { + std::string_view data = R"( +let a:R, a = 4; +let non_pure : R -> R, x -> x + a++; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("-- outer variable") + { + std::string_view data = R"( +let a:R, a = 4; +let non_pure : R -> R, x -> x * --a; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + + SECTION("outer variable --") + { + std::string_view data = R"( +let a:R, a = 4; +let non_pure : R -> R, x -> x + a--; +)"; + + CHECK_EXPRESSION_BUILDER_THROWS_WITH(data, std::string{ + "invalid function definition. Function data must be constant!"}); + } + } + } } }