NEURON
nmodl::test_utils Namespace Reference

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

Classes

struct  NmodlTestCase
 represent nmodl test construct More...
 
struct  DiffEqTestCase
 represent differential equation test construct More...
 
class  LoggerCapture
 

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, int indent_level)
 Reindent nmodl text for text-to-text comparison. More...
 

Variables

std::map< std::string, NmodlTestCase > const nmodl_invalid_constructs
 Guidelines for adding nmodl text constructs. More...
 
std::map< std::string, NmodlTestCase > const nmodl_valid_constructs
 
std::vector< DiffEqTestCase > const diff_eq_constructs
 

Detailed Description

custom type to represent nmodl construct for testing

Function Documentation

◆ count_leading_spaces()

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

Definition at line 19 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 28 of file test_utils.cpp.

◆ reindent_text()

std::string nmodl::test_utils::reindent_text ( const std::string &  text,
int  indent_level 
)

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 55 of file test_utils.cpp.

Variable Documentation

◆ diff_eq_constructs

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

Definition at line 1309 of file nmodl_constructs.cpp.

◆ nmodl_invalid_constructs

std::map< std::string, NmodlTestCase > const 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
static int c
Definition: hoc.cpp:169
  • Use well indented blocks
NEURON {
}
#define RANGE
Definition: errcodes.h:62

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

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

Definition at line 181 of file nmodl_constructs.cpp.