User Guide
nmodl::test_utils Namespace Reference

custom type to represent nmodl construct for testing More...

Detailed Description

custom type to represent nmodl construct for testing

Classes

struct  DiffEqTestCase
 represent differential equation test construct More...
 
struct  NmodlTestCase
 represent nmodl test construct More...
 
struct  TempFile
 Create an empty file which is then removed when the C++ object is destructed. More...
 

Functions

int count_leading_spaces (std::string text)
 
bool is_empty (const std::string &text)
 check if string has only whitespaces More...
 
std::string reindent_text (const std::string &text)
 Reindent nmodl text for text-to-text comparison. More...
 

Variables

const std::map< std::string, NmodlTestCasenmodl_invalid_constructs
 Guidelines for adding nmodl text constructs. More...
 
const std::map< std::string, NmodlTestCasenmodl_valid_constructs
 
const std::vector< DiffEqTestCasediff_eq_constructs
 

Function Documentation

◆ count_leading_spaces()

int nmodl::test_utils::count_leading_spaces ( std::string  text)

Definition at line 21 of file test_utils.cpp.

◆ is_empty()

bool nmodl::test_utils::is_empty ( const std::string &  text)

check if string has only whitespaces

Definition at line 30 of file test_utils.cpp.

◆ reindent_text()

std::string nmodl::test_utils::reindent_text ( const std::string &  text)

Reindent nmodl text for text-to-text comparison.

Nmodl constructs defined in test database has extra leading whitespace. This is done for readability reason in nmodl_constructs.cpp. For example, we have following nmodl text with 8 leading whitespaces:

    NEURON {
        RANGE x
    }

We convert above paragraph to:

NEURON { RANGE x }

i.e. we get first non-empty line and count number of leading whitespaces (X). Then for every sub-sequent line, we remove first X characters (assuming those all are whitespaces). This is done because when ast is transformed back to nmodl, the nmodl output is without "extra" whitespaces in the provided input.

count whitespaces for first non-empty line only

make sure we don't remove non whitespaces characters

discard empty lines at very beginning

Definition at line 57 of file test_utils.cpp.

Variable Documentation

◆ diff_eq_constructs

const std::vector< DiffEqTestCase > nmodl::test_utils::diff_eq_constructs

Definition at line 1309 of file nmodl_constructs.cpp.

◆ nmodl_invalid_constructs

const std::map< std::string, NmodlTestCase > nmodl::test_utils::nmodl_invalid_constructs

Guidelines for adding nmodl text constructs.

As nmodl constructs are used to for testing ast to nmodl transformations, consider following points:

  • Leading whitespaces or empty lines are removed
  • Use string literal to define nmodl text When ast is transformed back to nmodl, each statement has newline. Hence for easy comparison, input nmodl should be null terminated. One way to use format:
R"(
TITLE nmodl title
)"
  • Do not use extra spaces (even though it's valid)
LOCAL a,b

instead of

LOCAL a, b, c
  • Use well indented blocks
NEURON {
}

instead of

NEURON {
}

If nmodl transformation is different from input, third argument could be provided with the expected nmodl.

Definition at line 63 of file nmodl_constructs.cpp.

◆ nmodl_valid_constructs

const std::map< std::string, NmodlTestCase > nmodl::test_utils::nmodl_valid_constructs

Definition at line 181 of file nmodl_constructs.cpp.

nmodl::ast::AstNodeType::RANGE
@ RANGE
type of ast::Range