NEURON
after_cvode_to_cnexp.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"
11 #include "parser/nmodl_driver.hpp"
12 #include "utils/test_utils.hpp"
17 
18 
19 using namespace nmodl;
20 using namespace visitor;
21 using namespace test;
22 using namespace test_utils;
23 
25 
26 
27 //=============================================================================
28 // AfterCVodeToCnexp visitor tests
29 //=============================================================================
30 
31 std::string run_after_cvode_to_cnexp_visitor(const std::string& text) {
33  const auto& ast = driver.parse_string(text);
34 
37 
38  // check that, after visitor rearrangement, parents are still up-to-date
40 
41  return to_nmodl(ast);
42 }
43 
44 
45 SCENARIO("AfterCVodeToCnexpVisitor changes after_cvode solver method to cnexp") {
46  GIVEN("Breakpoint block with after_cvode method") {
47  std::string nmodl_text = R"(
48  BREAKPOINT {
49  SOLVE states METHOD after_cvode
50  }
51  )";
52 
53  std::string output_nmodl = R"(
54  BREAKPOINT {
55  SOLVE states METHOD cnexp
56  }
57  )";
58 
59  THEN("AfterCVodeToCnexp visitor replaces after_cvode solver with cnexp") {
60  std::string input = reindent_text(nmodl_text);
61  auto expected_result = reindent_text(output_nmodl);
63  REQUIRE(result == expected_result);
64  }
65  }
66 }
std::string run_after_cvode_to_cnexp_visitor(const std::string &text)
SCENARIO("AfterCVodeToCnexpVisitor changes after_cvode solver method to cnexp")
Visitor to change usage of after_cvode solver to cnexp.
Visitor for checking parents of ast nodes
Class that binds all pieces together for parsing nmodl file.
Visitor to change usage of after_cvode solver to cnexp.
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
Visitor for checking parents of ast nodes
int check_ast(const ast::Ast &node)
A small wrapper to have a nicer call in parser.cpp.
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.
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
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.