|
| 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 "ast/program.hpp" |
| 9 | +#include "parser/nmodl_driver.hpp" |
| 10 | +#include "utils/test_utils.hpp" |
| 11 | +#include "visitors/implicit_method_visitor.hpp" |
| 12 | +#include "visitors/nmodl_visitor.hpp" |
| 13 | +#include "visitors/symtab_visitor.hpp" |
| 14 | +#include "visitors/visitor_utils.hpp" |
| 15 | + |
| 16 | +#include <catch2/catch_test_macros.hpp> |
| 17 | +#include <catch2/matchers/catch_matchers_string.hpp> |
| 18 | + |
| 19 | +using namespace nmodl; |
| 20 | +using nmodl::test_utils::reindent_text; |
| 21 | + |
| 22 | +using Catch::Matchers::ContainsSubstring; // ContainsSubstring in newer Catch2 |
| 23 | + |
| 24 | +//============================================================================= |
| 25 | +// Implicit visitor tests |
| 26 | +//============================================================================= |
| 27 | + |
| 28 | +std::string generate_mod_after_implicit_method_visitor(std::string const& text) { |
| 29 | + parser::NmodlDriver driver{}; |
| 30 | + auto const ast = driver.parse_string(text); |
| 31 | + visitor::SymtabVisitor{}.visit_program(*ast); |
| 32 | + visitor::ImplicitMethodVisitor{}.visit_program(*ast); |
| 33 | + return to_nmodl(*ast); |
| 34 | +} |
| 35 | + |
| 36 | +SCENARIO("Check insertion of explicit arguments to SOLVE block", "[codegen][implicit_methods]") { |
| 37 | + GIVEN("A mod file that has a SOLVE block of a derivative without an explicit METHOD") { |
| 38 | + auto const nmodl_text = R"( |
| 39 | + NEURON { |
| 40 | + SUFFIX ImplicitMethodTest |
| 41 | + } |
| 42 | +
|
| 43 | + BREAKPOINT { |
| 44 | + SOLVE states |
| 45 | + } |
| 46 | +
|
| 47 | + ASSIGNED { |
| 48 | + n |
| 49 | + } |
| 50 | +
|
| 51 | + DERIVATIVE states { |
| 52 | + n' = -n |
| 53 | + } |
| 54 | + )"; |
| 55 | + auto const expected_text = R"( |
| 56 | + NEURON { |
| 57 | + SUFFIX ImplicitMethodTest |
| 58 | + } |
| 59 | +
|
| 60 | + BREAKPOINT { |
| 61 | + SOLVE states METHOD derivimplicit |
| 62 | + } |
| 63 | +
|
| 64 | + ASSIGNED { |
| 65 | + n |
| 66 | + } |
| 67 | +
|
| 68 | + DERIVATIVE states { |
| 69 | + n' = -n |
| 70 | + } |
| 71 | + )"; |
| 72 | + auto const actual_text = generate_mod_after_implicit_method_visitor(nmodl_text); |
| 73 | + THEN("at_time should have nt as its first argument") { |
| 74 | + REQUIRE(reindent_text(actual_text) == reindent_text(expected_text)); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments