8 #include <catch2/catch_test_macros.hpp> 
   17 using namespace nmodl;
 
   18 using namespace visitor;
 
   19 using namespace test_utils;
 
   30     SymtabVisitor().visit_program(*ast);
 
   31     return SemanticAnalysisVisitor{}.check(*ast);
 
   34 SCENARIO(
"TABLE stmt", 
"[visitor][semantic_analysis]") {
 
   35     GIVEN(
"Procedure with more than one argument") {
 
   36         std::string nmodl_text = R
"( 
   37             PROCEDURE rates_1(a, b) { 
   38                 TABLE ainf FROM 0 TO 1 WITH 1 
   46     GIVEN(
"Procedure with exactly one argument") {
 
   47         std::string nmodl_text = R
"( 
   48             PROCEDURE rates_1(a) { 
   49                 TABLE ainf FROM 0 TO 1 WITH 1 
   57     GIVEN(
"Procedure with less than one argument") {
 
   58         std::string nmodl_text = R
"( 
   60                 TABLE ainf FROM 0 TO 1 WITH 1 
   68     GIVEN(
"Two procedures which use a table and have the same variable") {
 
   69         std::string nmodl_text = R
"( 
   71                 TABLE var FROM 0 TO 1 WITH 10 
   75                 TABLE var FROM 0 TO 1 WITH 10 
   87 SCENARIO(
"Destructor block", 
"[visitor][semantic_analysis]") {
 
   88     GIVEN(
"A point-process mod file, with a destructor") {
 
   89         std::string nmodl_text = R
"( 
   90             DESTRUCTOR { : Destructor is before 
  101     GIVEN(
"A artifial-cell mod file, with a destructor") {
 
  102         std::string nmodl_text = R
"( 
  114     GIVEN(
"A non point-process mod file, with a destructor") {
 
  115         std::string nmodl_text = R
"( 
  128 SCENARIO(
"Ion variable in CONSTANT block", 
"[visitor][semantic_analysis]") {
 
  129     GIVEN(
"A mod file with ion variable redeclared in a CONSTANT block") {
 
  130         std::string nmodl_text = R
"( 
  133                 USEION ca READ cao, cai, ica WRITE cai 
  135             CONSTANT { cao = 2  (mM) } 
  137         THEN("Semantic analysis fails") {
 
  143 SCENARIO(
"INDEPENDENT block", 
"[visitor][semantic_analysis]") {
 
  144     GIVEN(
"A mod file with Independent block with only t") {
 
  145         std::string nmodl_text = R
"( 
  147                 t FROM 0 TO 1 WITH 100 
  150         THEN("Semantic analysis succeed") {
 
  154     GIVEN(
"A mod file with Independent block with something else than t") {
 
  155         std::string nmodl_text = R
"( 
  157                 t FROM 0 TO 1 WITH 100 
  158                 u FROM 0 TO 1 WITH 100 
  161         THEN("Semantic analysis fails") {
 
  167 SCENARIO(
"FUNCTION_TABLE block", 
"[visitor][semantic_analysis]") {
 
  168     GIVEN(
"A mod file with FUNCTION_TABLE without argument") {
 
  169         std::string nmodl_text = R
"( 
  172         THEN("Semantic analysis should fail") {
 
  176     GIVEN(
"A mod file with FUNCTION_TABLE with at least one argument") {
 
  177         std::string nmodl_text = R
"( 
  178             FUNCTION_TABLE ttt(w (mV)) 
  180         THEN("Semantic analysis should success") {
 
  187 SCENARIO(
"At most one DERIVATIVE block", 
"[visitor][semantic_analysis]") {
 
  188     GIVEN(
"Only one DERIVATIVE block") {
 
  189         std::string nmodl_text = R
"( 
  194         THEN("Semantic analysis should success") {
 
  198     GIVEN(
"2 DERIVATIVE blocks") {
 
  199         std::string nmodl_text = R
"( 
  207         THEN("Semantic analysis should failed") {
 
  213 SCENARIO(
"RANDOM Construct", 
"[visitor][semantic_analysis]") {
 
  214     GIVEN(
"A mod file with correct RANDOM variable usage") {
 
  215         std::string nmodl_text = R
"( 
  222                 x = 1 + random_negexp(r) 
  223                 x = x + exp(random_negexp(r)) 
  226                  erand = random_negexp(r) 
  229         THEN("Semantic analysis should pass") {
 
  234     GIVEN(
"A mod file with incorrect usage of RANDOM variable as function arguments") {
 
  235         std::string nmodl_text = R
"( 
  243         THEN("Semantic analysis should faial") {
 
  248     GIVEN(
"A mod file with incorrect usage of RANDOM variable in an expression") {
 
  249         std::string nmodl_text = R
"( 
  258         THEN("Semantic analysis should fail") {
 
  263     GIVEN(
"A mod file with incorrect usage of RANDOM variable in non-random function") {
 
  264         std::string nmodl_text = R
"( 
  273         THEN("Semantic analysis should fail") {
 
  279 SCENARIO(
"RANGE and FUNCTION/PROCEDURE block", 
"[visitor][semantic_analysis]") {
 
  280     GIVEN(
"A mod file with same RANGE var name and a FUNCTION name") {
 
  281         std::string nmodl_text = R
"( 
  289         THEN("Semantic analysis should fail") {
 
  293     GIVEN(
"A mod file with same RANGE var name and a PROCEDURE name") {
 
  294         std::string nmodl_text = R
"( 
  301         THEN("Semantic analysis should fail") {