8 #include <catch2/catch_test_macros.hpp>
18 using namespace nmodl;
19 using namespace visitor;
21 using namespace test_utils;
33 SymtabVisitor().visit_program(*ast);
34 ConstantFolderVisitor().visit_program(*ast);
36 std::stringstream stream;
37 NmodlPrintVisitor(stream).visit_program(*ast);
40 CheckParentVisitor().check_ast(*ast);
45 SCENARIO(
"Perform constant folder on NMODL constructs") {
46 GIVEN(
"Simple integer expression") {
47 std::string nmodl_text = R
"(
52 std::string expected_text = R"(
57 THEN("successfully folds") {
63 GIVEN(
"Simple double expression") {
64 std::string nmodl_text = R
"(
69 std::string expected_text = R"(
74 THEN("successfully folds") {
80 GIVEN(
"Complex expression") {
81 std::string nmodl_text = R
"(
83 a = 1 + (2) + (2 / 2) + (((1+((2)))))
86 std::string expected_text = R"(
91 THEN("successfully folds") {
97 GIVEN(
"Integer expression with define statement") {
98 std::string nmodl_text = R
"(
102 a = N + (2*N) + (N / 2) + (((1+((N)))))
107 std::string expected_text = R"(
116 THEN("successfully folds") {
122 GIVEN(
"Only fold part of the statement") {
123 std::string nmodl_text = R
"(
133 std::string expected_text = R"(
143 THEN("successfully folds and keep other statements untouched") {
149 GIVEN(
"Don't remove parentheses if not simplifying") {
150 std::string nmodl_text = R
"(
154 a = ((N+1)+5)*(c+1+N)/(b - 2)
157 std::string expected_text = R"(
161 a = 16*(c+1+10)/(b-2)
164 THEN("successfully folds and keep other statements untouched") {