8 #include <catch2/catch_test_macros.hpp>
9 #include <catch2/matchers/catch_matchers_string.hpp>
21 using Catch::Matchers::ContainsSubstring;
23 using namespace nmodl;
24 using namespace visitor;
25 using namespace codegen;
33 const std::shared_ptr<ast::Program>& ast,
35 std::stringstream& ss) {
37 SymtabVisitor().visit_program(*ast);
40 InlineVisitor().visit_program(*ast);
41 NeuronSolveVisitor().visit_program(*ast);
42 SolveBlockVisitor().visit_program(*ast);
43 FunctionCallpathVisitor().visit_program(*ast);
45 bool optimize_ion_vars =
false;
46 bool enable_cvode =
true;
49 auto cv = std::make_shared<CodegenNeuronCppVisitor>(
50 "_test", ss,
"double", optimize_ion_vars, enable_cvode);
54 SCENARIO(
"Check whether PROCEDURE and FUNCTION need setdata call",
"[codegen][needsetdata]") {
55 GIVEN(
"mod file with GLOBAL and RANGE variables used in FUNC and PROC") {
56 std::string input_nmodl = R
"(
81 cvisitor->visit_program(*ast);
82 const auto symtab = ast->get_symbol_table();
83 THEN(
"use_range_ptr_var property is added to needed FUNC and PROC") {
84 auto use_range_ptr_var_funcs = symtab->get_variables_with_properties(
85 NmodlType::use_range_ptr_var);
86 REQUIRE(use_range_ptr_var_funcs.size() == 2);
87 const auto a = symtab->lookup(
"a");
88 REQUIRE(a->has_any_property(NmodlType::use_range_ptr_var));
89 const auto b = symtab->lookup(
"b");
90 REQUIRE(b->has_any_property(NmodlType::use_range_ptr_var));
91 const auto get_42 = symtab->lookup(
"get_42");
92 REQUIRE(!get_42->has_any_property(NmodlType::use_range_ptr_var));
98 std::string pattern = R
"(
111 return fmt::format(pattern, var);
115 std::string pattern = R
"(
130 return fmt::format(pattern, var);
135 std::stringstream ss;
137 cvisitor->visit_program(*ast);
143 GIVEN(
"mod file that writes to `cao`") {
146 THEN(
"it contains") {
147 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_check_conc_write(_prop, ca_prop, 0);"));
148 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop, ca_prop, 1);"));
149 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 3, 0);"));
150 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_wrote_conc("));
156 GIVEN(
"mod file that writes to `cai`") {
159 THEN(
"it contains") {
160 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop, ca_prop, 0);"));
161 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_check_conc_write(_prop, ca_prop, 1);"));
162 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 3, 0);"));
163 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_wrote_conc("));
169 GIVEN(
"mod file that writes to `eca`") {
172 THEN(
"it contains") {
173 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop,"));
174 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 0, 3);"));
175 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_wrote_conc("));
181 GIVEN(
"mod file that reads to `cao`") {
184 THEN(
"it contains") {
185 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop,"));
186 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 1, 0);"));
187 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_wrote_conc("));
193 GIVEN(
"mod file that reads to `cai`") {
196 THEN(
"it contains") {
197 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop,"));
198 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 1, 0);"));
199 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_wrote_conc("));
205 GIVEN(
"mod file that reads to `eca`") {
208 THEN(
"it contains") {
209 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_check_conc_write(_prop,"));
210 REQUIRE_THAT(cpp, ContainsSubstring(
"nrn_promote(ca_prop, 0, 1);"));
211 REQUIRE_THAT(cpp, !ContainsSubstring(
"nrn_wrote_conc("));
217 GIVEN(
"a mod file") {
218 std::string
nmodl = R
"(
228 THEN("it contains") {
229 REQUIRE_THAT(cpp, ContainsSubstring(
"artcell_net_send"));
235 GIVEN(
"a mod file") {
236 std::string
nmodl = R
"(
246 THEN("it contains") {
247 REQUIRE_THAT(cpp, ContainsSubstring(
"artcell_net_move"));