Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code generation test for CONSTANT block #981

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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