1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/*************************************************************************
* Copyright (C) 2022 Blue Brain Project
*
* This file is part of NMODL distributed under the terms of the GNU
* Lesser General Public License. See top-level LICENSE file for details.
*************************************************************************/
#include <catch2/catch_test_macros.hpp>
#include "ast/program.hpp"
#include "codegen/codegen_transform_visitor.hpp"
#include "parser/nmodl_driver.hpp"
#include "test/unit/utils/test_utils.hpp"
#include "visitors/nmodl_visitor.hpp"
using namespace nmodl;
using namespace visitor;
using namespace test_utils;
using nmodl::parser::NmodlDriver;
//=============================================================================
// Variable rename tests
//=============================================================================
static std::string run_transform_visitor(const std::string& text) {
NmodlDriver driver;
const auto& ast = driver.parse_string(text);
CodegenTransformVisitor{}.visit_program(*ast);
std::stringstream stream;
NmodlPrintVisitor(stream).visit_program(*ast);
return stream.str();
}
SCENARIO("Adding a variable for a table inside a function", "[visitor][transform]") {
GIVEN("A mod file with a table inside a function") {
// sample nmodl text
std::string input_nmodl_text = R"(
FUNCTION mAlpha(v) {
TABLE FROM 0 TO 150 WITH 1
mAlpha = 1
}
)";
/// expected result after adding the variable
std::string output_nmodl_text = R"(
FUNCTION mAlpha(v) {
TABLE mAlpha FROM 0 TO 150 WITH 1
mAlpha = 1
}
)";
std::string input = reindent_text(input_nmodl_text);
std::string expected_output = reindent_text(output_nmodl_text);
THEN("variable has been added") {
auto result = run_transform_visitor(input);
REQUIRE(result == expected_output);
}
}
}
|