Skip to content

Commit

Permalink
Add code generation test for CONSTANT block (#981)
Browse files Browse the repository at this point in the history
* code generation is already implemented in
    https://github.com/BlueBrain/nmodl/blob/25cd4707d2a4cf7f47febeb9ba321ff2dc30244c/src/codegen/codegen_helper_visitor.cpp#L158
    https://github.com/BlueBrain/nmodl/blob/9602bddb83c55a0a3cb64661b156bb37270fdaaf/src/codegen/codegen_cpp_visitor.cpp#L2606

 * add test to make sure variables are added as part of
   mech_Store struct that contain all global variables

fixes #945

Co-authored-by: Ioannis Magkanaris <[email protected]>
  • Loading branch information
pramodk and iomaganaris authored Jan 5, 2023
1 parent de6e3e3 commit 04c4e3d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions test/unit/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ SCENARIO("Check code generation for TABLE statements", "[codegen][array_variable
}
}

SCENARIO("Check CONSTANT variables are added to global variable structure",
"[codegen][global_variables]") {
GIVEN("A MOD file that use CONSTANT variables") {
std::string const nmodl_text = R"(
NEURON {
SUFFIX CONST
GLOBAL zGateS1
}
PARAMETER {
zGateS1 = 1.2 (1)
}
CONSTANT {
e0 = 1.60217646e-19 (coulombs)
kB = 1.3806505e-23 (joule/kelvin)
q10Fluo = 1.67 (1)
}
)";
THEN("The global struct should contain these variables") {
auto const generated = get_cpp_code(nmodl_text);
std::string expected_code = R"(
struct CONST_Store {
int reset{};
int mech_type{};
double zGateS1{1.2};
double e0{1.60218e-19};
double kB{1.38065e-23};
double q10Fluo{1.67};
};)";
REQUIRE_THAT(generated, Contains(reindent_text(stringutils::trim(expected_code))));
}
}
}

SCENARIO("Check code generation for FUNCTION_TABLE block", "[codegen][function_table]") {
GIVEN("A MOD file with Function table block") {
std::string const nmodl_text = R"(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/utils/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NEURON {
}
* i.e. we get first non-empty line and count number of leading whitespaces (X).
* Then for every sub-sequent line, we remove first X characters (assuing those
* Then for every sub-sequent line, we remove first X characters (assuming those
* all are whitespaces). This is done because when ast is transformed back to
* nmodl, the nmodl output is without "extra" whitespaces in the provided input.
*/
Expand Down

0 comments on commit 04c4e3d

Please sign in to comment.