From 04c4e3dc6a8c28bf95b376393501fbe8a98ef74f Mon Sep 17 00:00:00 2001 From: Pramod Kumbhar Date: Thu, 5 Jan 2023 16:50:50 +0530 Subject: [PATCH] Add code generation test for CONSTANT block (#981) * 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 --- test/unit/codegen/codegen_cpp_visitor.cpp | 33 +++++++++++++++++++++++ test/unit/utils/test_utils.cpp | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/test/unit/codegen/codegen_cpp_visitor.cpp b/test/unit/codegen/codegen_cpp_visitor.cpp index 880519f39e..36750a91b1 100644 --- a/test/unit/codegen/codegen_cpp_visitor.cpp +++ b/test/unit/codegen/codegen_cpp_visitor.cpp @@ -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"( diff --git a/test/unit/utils/test_utils.cpp b/test/unit/utils/test_utils.cpp index c1f88fccac..7f6e81841b 100644 --- a/test/unit/utils/test_utils.cpp +++ b/test/unit/utils/test_utils.cpp @@ -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. */