User Guide
rename_function_arguments.cpp
Go to the documentation of this file.
1 #include <catch2/catch_test_macros.hpp>
2 #include <catch2/matchers/catch_matchers_string.hpp>
3 
4 #include "ast/program.hpp"
8 
9 using namespace nmodl;
10 using namespace visitor;
11 
12 using Catch::Matchers::ContainsSubstring;
14 
15 
16 TEST_CASE("Rename function arguments") {
17  std::string mod_code = R"(
18 NEURON {
19  RANGE tau
20 }
21 
22 FUNCTION foo(a, v, cai) {
23  exp(tau + a + v*cai)
24 }
25 
26 PROCEDURE bar(tau, a, b, d) {
27  foo(tau, a*b, d)
28 }
29 )";
30 
32  const auto& ast = driver.parse_string(mod_code);
33 
35  visitor.visit_program(*ast);
36 
37  auto transformed_mod = nmodl::to_nmodl(*ast);
38 
39  SECTION("FUNCTION") {
40  std::string expected = R"(
41 FUNCTION foo(_la, _lv, _lcai) {
42  exp(tau+_la+_lv*_lcai)
43 }
44 )";
45 
46  REQUIRE_THAT(transformed_mod, ContainsSubstring(expected));
47  }
48 
49  SECTION("PROCEDURE") {
50  std::string expected = R"(
51 PROCEDURE bar(_ltau, _la, _lb, _ld) {
52  foo(_ltau, _la*_lb, _ld)
53 }
54 )";
55 
56  REQUIRE_THAT(transformed_mod, ContainsSubstring(expected));
57  }
58 }
nmodl::parser::NmodlDriver
Class that binds all pieces together for parsing nmodl file.
Definition: nmodl_driver.hpp:67
nmodl::to_nmodl
std::string to_nmodl(const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types)
Given AST node, return the NMODL string representation.
Definition: visitor_utils.cpp:234
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
rename_function_arguments.hpp
visitor_utils.hpp
Utility functions for visitors implementation.
nmodl::visitor::RenameFunctionArgumentsVisitor
Definition: rename_function_arguments.hpp:10
program.hpp
Auto generated AST classes declaration.
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
TEST_CASE
TEST_CASE("Rename function arguments")
Definition: rename_function_arguments.cpp:16
nmodl::parser::UnitDriver::parse_string
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
nmodl_driver.hpp