File: implicit_argument.cpp

package info (click to toggle)
nmodl 0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,016 kB
  • sloc: cpp: 28,492; javascript: 9,841; yacc: 2,804; python: 1,971; lex: 1,674; xml: 181; sh: 136; ansic: 37; makefile: 17; pascal: 7
file content (61 lines) | stat: -rw-r--r-- 2,616 bytes parent folder | download | duplicates (2)
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
/*************************************************************************
 * 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 "parser/nmodl_driver.hpp"
#include "test/unit/utils/test_utils.hpp"
#include "visitors/implicit_argument_visitor.hpp"
#include "visitors/nmodl_visitor.hpp"
#include "visitors/symtab_visitor.hpp"
#include "visitors/visitor_utils.hpp"

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

using namespace nmodl;
using nmodl::test_utils::reindent_text;

using Catch::Matchers::ContainsSubstring;  // ContainsSubstring in newer Catch2

//=============================================================================
// Implicit visitor tests
//=============================================================================

std::string generate_mod_after_implicit_argument_visitor(std::string const& text) {
    parser::NmodlDriver driver{};
    auto const ast = driver.parse_string(text);
    visitor::SymtabVisitor{}.visit_program(*ast);
    visitor::ImplicitArgumentVisitor{}.visit_program(*ast);
    return to_nmodl(*ast);
}

SCENARIO("Check insertion of implicit arguments", "[codegen][implicit_arguments]") {
    GIVEN("A mod file that calls functions that may need implicit arguments") {
        auto const nmodl_text = R"(
            NEURON {
                SUFFIX ImplicitTest
            }
            INITIAL {
                at_time(foo)
                at_time(a+b)
                at_time(nt, flop)
                nrn_ghk(-50(mV), .001(mM), 10(mM), 2)
                nrn_ghk(-50(mV), .001(mM), 10(mM), 2, -273.15)
            }
        )";
        auto const modified_nmodl = generate_mod_after_implicit_argument_visitor(nmodl_text);
        THEN("at_time should have nt as its first argument") {
            REQUIRE_THAT(modified_nmodl, ContainsSubstring("at_time(nt, foo)"));
            REQUIRE_THAT(modified_nmodl, ContainsSubstring("at_time(nt, a+b)"));
            REQUIRE_THAT(modified_nmodl, ContainsSubstring("at_time(nt, flop)"));
        }
        THEN("nrn_ghk should have a temperature as its last argument") {
            REQUIRE_THAT(modified_nmodl,
                         ContainsSubstring("nrn_ghk(-50(mV), .001(mM), 10(mM), 2, celsius)"));
            REQUIRE_THAT(modified_nmodl,
                         ContainsSubstring("nrn_ghk(-50(mV), .001(mM), 10(mM), 2, -273.15)"));
        }
    }
}