NEURON
solve_without_method.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include "ast/program.hpp"
10 #include "utils/test_utils.hpp"
15 
16 #include <catch2/catch_test_macros.hpp>
17 #include <catch2/matchers/catch_matchers_string.hpp>
18 
19 using namespace nmodl;
21 
22 //=============================================================================
23 // Solve without method visitor tests
24 //=============================================================================
25 
26 std::string generate_mod_after_solve_without_method_visitor(std::string const& text) {
28  auto const ast = driver.parse_string(text);
31  return to_nmodl(*ast);
32 }
33 
34 SCENARIO("Check insertion of explicit METHOD to SOLVE block", "[visitor][solve_without_method]") {
35  GIVEN("A mod file that has a SOLVE block of a derivative without an explicit METHOD") {
36  auto const nmodl_text = R"(
37  NEURON {
38  SUFFIX ImplicitMethodTest
39  }
40 
41  BREAKPOINT {
42  SOLVE states
43  }
44 
45  STATE {
46  n
47  }
48 
49  DERIVATIVE states {
50  n' = -n
51  }
52  )";
53  auto const expected_text = R"(
54  NEURON {
55  SUFFIX ImplicitMethodTest
56  }
57 
58  BREAKPOINT {
59  SOLVE states METHOD derivimplicit
60  }
61 
62  STATE {
63  n
64  }
65 
66  DERIVATIVE states {
67  n' = -n
68  }
69  )";
71  THEN("The two mod files should match") {
72  REQUIRE(reindent_text(actual_text) == reindent_text(expected_text));
73  }
74  }
75  GIVEN("A mod file that has a SOLVE block of a derivative with an explicit METHOD") {
76  auto const nmodl_text = R"(
77  NEURON {
78  SUFFIX ImplicitMethodTest
79  }
80 
81  BREAKPOINT {
82  SOLVE states METHOD cnexp
83  }
84 
85  STATE {
86  n
87  }
88 
89  DERIVATIVE states {
90  n' = -n
91  }
92  )";
94  THEN("The mod file should remain as-is") {
95  REQUIRE(reindent_text(actual_text) == reindent_text(nmodl_text));
96  }
97  }
98  GIVEN("A mod file that has a SOLVE block of a LINEAR block without an explicit METHOD") {
99  auto const nmodl_text = R"(
100  NEURON {
101  SUFFIX ImplicitMethodTest
102  }
103 
104  BREAKPOINT {
105  SOLVE states
106  }
107 
108  STATE {
109  x
110  }
111 
112  LINEAR lin {
113  ~ 2*a*x = 1
114  }
115  )";
117  THEN("The mod file should remain as-is") {
118  REQUIRE(reindent_text(actual_text) == reindent_text(nmodl_text));
119  }
120  }
121 }
Class that binds all pieces together for parsing nmodl file.
Visitor for adding an explicit method to a SOLVE block which has an implicit one
void visit_program(ast::Program &node) override
visit node of type ast::Program
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
int nmodl_text
Definition: modl.cpp:58
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
Definition: test_utils.cpp:55
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
std::string to_nmodl(const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types)
Given AST node, return the NMODL string representation.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
SCENARIO("Check insertion of explicit METHOD to SOLVE block", "[visitor][solve_without_method]")
std::string generate_mod_after_solve_without_method_visitor(std::string const &text)
Visitor for adding an explicit method to a SOLVE block which has an implicit one
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
Utility functions for visitors implementation.