NEURON
verbatim.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"
14 
15 using namespace nmodl;
16 using namespace visitor;
17 using namespace test;
19 
20 
21 //=============================================================================
22 // Verbatim visitor tests
23 //=============================================================================
24 
25 std::vector<std::string> run_verbatim_visitor(const std::string& text) {
27  const auto& ast = driver.parse_string(text);
28 
30  v.visit_program(*ast);
31 
32  // check that, after visitor rearrangement, parents are still up-to-date
34 
35  return v.verbatim_blocks();
36 }
37 
38 TEST_CASE("Parse VERBATIM block using Verbatim Visitor") {
39  SECTION("Single Block") {
40  const std::string text = "VERBATIM int a; ENDVERBATIM";
41  auto blocks = run_verbatim_visitor(text);
42 
43  REQUIRE(blocks.size() == 1);
44  REQUIRE(blocks.front() == " int a; ");
45  }
46 
47  SECTION("Multiple Blocks") {
48  std::string text = "VERBATIM int a; ENDVERBATIM VERBATIM float b; ENDVERBATIM";
49  auto blocks = run_verbatim_visitor(text);
50 
51  REQUIRE(blocks.size() == 2);
52  REQUIRE(blocks[0] == " int a; ");
53  REQUIRE(blocks[1] == " float b; ");
54  }
55 }
Visitor for checking parents of ast nodes
Class that binds all pieces together for parsing nmodl file.
Visitor for verbatim blocks of AST
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.
#define v
Definition: md1redef.h:11
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
TEST_CASE("Parse VERBATIM block using Verbatim Visitor")
Definition: verbatim.cpp:38
std::vector< std::string > run_verbatim_visitor(const std::string &text)
Definition: verbatim.cpp:25
Visitor for verbatim blocks of AST