NEURON
transform.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <catch2/catch_test_macros.hpp>
9 
10 #include "ast/program.hpp"
12 #include "parser/nmodl_driver.hpp"
13 #include "utils/test_utils.hpp"
15 
16 using namespace nmodl;
17 using namespace visitor;
18 using namespace test_utils;
19 
21 
22 
23 //=============================================================================
24 // Variable rename tests
25 //=============================================================================
26 
27 static std::string run_transform_visitor(const std::string& text) {
29  const auto& ast = driver.parse_string(text);
31  std::stringstream stream;
32  NmodlPrintVisitor(stream).visit_program(*ast);
33 
34  return stream.str();
35 }
36 
37 SCENARIO("Adding a variable for a table inside a function", "[visitor][transform]") {
38  GIVEN("A mod file with a table inside a function") {
39  // sample nmodl text
40  std::string input_nmodl_text = R"(
41  FUNCTION mAlpha(v) {
42  TABLE FROM 0 TO 150 WITH 1
43  mAlpha = 1
44  }
45  )";
46 
47  /// expected result after adding the variable
48  std::string output_nmodl_text = R"(
49  FUNCTION mAlpha(v) {
50  TABLE mAlpha FROM 0 TO 150 WITH 1
51  mAlpha = 1
52  }
53  )";
54 
55  std::string input = reindent_text(input_nmodl_text);
56  std::string expected_output = reindent_text(output_nmodl_text);
57 
58  THEN("variable has been added") {
59  auto result = run_transform_visitor(input);
60  REQUIRE(result == expected_output);
61  }
62  }
63 }
Visitor to make last transformation to AST before codegen.
Class that binds all pieces together for parsing nmodl file.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Visitor for printing AST back to NMODL
void visit_program(const ast::Program &node) override
visit node of type ast::Program
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
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
static std::string run_transform_visitor(const std::string &text)
Definition: transform.cpp:27
SCENARIO("Adding a variable for a table inside a function", "[visitor][transform]")
Definition: transform.cpp:37
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28