20 #include <catch2/catch_test_macros.hpp>
21 #include <catch2/matchers/catch_matchers_string.hpp>
23 using namespace nmodl;
26 using Catch::Matchers::ContainsSubstring;
32 template <
typename block_type, ast::AstNodeType node_type>
40 SCENARIO(
"Check multiple INITIAL blocks are handled properly",
41 "[visitor][merge_top_level_blocks]") {
42 GIVEN(
"A mod file with multiple empty top-level INITIAL blocks") {
43 const auto nmodl_text_before = R
"(
45 SUFFIX InitialBlockTest
55 const auto nmodl_text_after = R
"(
57 SUFFIX InitialBlockTest
65 const auto program_expected =
to_nmodl(ast_expected);
66 const auto program_actual =
70 THEN(
"expected and actual should be identical at the level of the AST") {
74 GIVEN(
"A mod file with an empty and a non-empty top-level INITIAL block") {
75 const auto nmodl_text_before = R
"(
77 SUFFIX InitialBlockTest
86 const auto nmodl_text_after = R
"(
88 SUFFIX InitialBlockTest
99 const auto program_expected =
to_nmodl(ast_expected);
100 const auto program_actual =
104 THEN(
"expected and actual should be identical at the level of the AST") {
108 GIVEN(
"A mod file with multiple non-empty INITIAL blocks") {
109 const auto nmodl_text_before = R
"(
111 SUFFIX InitialBlockTest
121 const auto nmodl_text_after = R
"(
123 SUFFIX InitialBlockTest
137 const auto program_expected =
to_nmodl(ast_expected);
138 const auto program_actual =
142 THEN(
"expected and actual should be identical at the level of the AST") {
146 GIVEN(
"A mod file with an INITIAL block only inside of a NET_RECEIVE block") {
147 const auto nmodl_text_before = R
"(
159 const auto program_actual =
163 THEN(
"leave the mod file as-is") {
167 GIVEN(
"A mod file with an INITIAL block, and one inside of a NET_RECEIVE block") {
173 const auto nmodl_text_before = R
"(
189 const auto nmodl_text_after = R
"(
209 const auto program_expected =
to_nmodl(ast_expected);
210 const auto program_actual =
214 THEN(
"leave the mod file as-is") {
220 SCENARIO(
"Check multiple BREAKPOINT blocks are handled properly",
221 "[visitor][merge_top_level_blocks]") {
222 GIVEN(
"A mod file with multiple BREAKPOINT blocks") {
223 const auto nmodl_text_before = R
"(
225 SUFFIX BreakpointBlockTest
235 const auto nmodl_text_after = R
"(
237 SUFFIX BreakpointBlockTest
251 const auto program_expected =
to_nmodl(ast_expected);
252 const auto program_actual =
256 THEN(
"expected and actual should be identical at the level of the AST") {
Auto generated AST classes declaration.
Represents a BREAKPOINT block in NMODL.
Represents a INITIAL block in the NMODL.
Class that binds all pieces together for parsing nmodl file.
Visitor which merges given top-level blocks into one.
void visit_program(ast::Program &node) override
visit node of type ast::Program
@ BREAKPOINT_BLOCK
type of ast::BreakpointBlock
@ INITIAL_BLOCK
type of ast::InitialBlock
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Auto generated AST classes declaration.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
SCENARIO("Check multiple INITIAL blocks are handled properly", "[visitor][merge_top_level_blocks]")
auto generate_mod_after_merge_top_level_blocks_visitor(std::string const &text)
Visitor which merges given top-level blocks into one.
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
encapsulates code generation backend implementations
std::string to_nmodl(const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types)
Given AST node, return the NMODL string representation.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
Auto generated AST classes declaration.
Auto generated AST classes declaration.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver
Utility functions for visitors implementation.