User Guide
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"
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 
35  SymtabVisitor().visit_program(*ast);
36  AfterCVodeToCnexpVisitor().visit_program(*ast);
37 
38  // check that, after visitor rearrangement, parents are still up-to-date
39  CheckParentVisitor().check_ast(*ast);
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);
62  auto result = run_after_cvode_to_cnexp_visitor(input);
63  REQUIRE(result == expected_result);
64  }
65  }
66 }
test_utils.hpp
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
SCENARIO
SCENARIO("AfterCVodeToCnexpVisitor changes after_cvode solver method to cnexp")
Definition: after_cvode_to_cnexp.cpp:45
nmodl::test_utils::reindent_text
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
Definition: test_utils.cpp:53
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
visitor_utils.hpp
Utility functions for visitors implementation.
program.hpp
Auto generated AST classes declaration.
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
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
after_cvode_to_cnexp_visitor.hpp
Visitor to change usage of after_cvode solver to cnexp.
checkparent_visitor.hpp
Visitor for checking parents of ast nodes
nmodl_driver.hpp
run_after_cvode_to_cnexp_visitor
std::string run_after_cvode_to_cnexp_visitor(const std::string &text)
Definition: after_cvode_to_cnexp.cpp:31
symtab_visitor.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.