Skip to content
Snippets Groups Projects
Commit 05e47704 authored by Vasileios Karakasis's avatar Vasileios Karakasis
Browse files

Adds unit tests for the STATE block.

parent 18a9226c
Branches
Tags
No related merge requests found
......@@ -10,8 +10,8 @@ NEURON {
}
STATE {
h (mA)
m (mV) r (S)
h (nA)
m r
}
UNITS {
......
......@@ -40,6 +40,15 @@ Module::Module(std::vector<char> const& buffer)
buffer_.push_back(0);
}
Module::Module(const char* buffer, size_t count)
{
for (auto i = 0; i < count-1 && *buffer != '\0'; ++buffer) {
buffer_.push_back(*buffer);
}
buffer_.push_back(0);
}
std::vector<Module::symbol_ptr>&
Module::procedures() {
return procedures_;
......
......@@ -15,6 +15,7 @@ public :
Module(std::string const& fname);
Module(std::vector<char> const& buffer);
Module(const char* buffer, size_t count);
std::vector<char> const& buffer() const {
return buffer_;
......
......@@ -39,9 +39,6 @@ public:
return error_string_;
}
private:
Module *module_;
// functions for parsing descriptive blocks
// these are called in the first pass, and do not
// construct any AST information
......@@ -52,6 +49,9 @@ private:
void parse_assigned_block();
void parse_title();
private:
Module *module_;
std::vector<Token> comma_separated_identifiers();
std::vector<Token> unit_description();
......@@ -69,4 +69,3 @@ private:
bool expect(tok, const char *str="");
bool expect(tok, std::string const& str);
};
......@@ -562,3 +562,39 @@ TEST(Parser, parse_binop) {
std::cout << red("error") << p.error_message() << std::endl;
}
}
TEST(Parser, parse_state_block) {
std::vector<const char*> state_blocks = {
"STATE {\n"
" h\n"
" m r\n"
"}",
"STATE {\n"
" h (nA)\n"
" m r\n"
"}",
"STATE {\n"
" h (nA)\n"
" m (nA) r\n"
"}",
"STATE {\n"
" h (nA)\n"
" m r (uA)\n"
"}",
"STATE {\n"
" h (nA)\n"
" m (nA) r (uA)\n"
"}"
};
for (auto const& str: state_blocks) {
Module m(str, sizeof(str));
Parser p(m, false);
p.parse_state_block();
EXPECT_EQ(lexerStatus::happy, p.status());
if (p.status() == lexerStatus::error) {
std::cout << str << "\n"
<< red("error") << p.error_message() << "\n";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment