1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 18:32:37 +02:00

Removed half the unit tests and fixed the rest of them.

This commit is contained in:
Stefan de Bruijn
2021-06-08 10:05:39 +02:00
parent ce688e363f
commit f38bc96195
3 changed files with 108 additions and 243 deletions

View File

@@ -21,52 +21,10 @@ namespace Configuration {
" shared_stepper_disable: gpio.13:low\n" " shared_stepper_disable: gpio.13:low\n"
" \n" " \n"
" x:\n" " x:\n"
" steps_per_mm: 800\n"
" max_rate: 2000\n"
" acceleration: 25\n"
" max_travel: 1000\n"
" home_mpos: 10\n"
" \n"
" gang0:\n"
" endstops:\n"
" dual: gpio.17:low:pu\n"
" stepstick:\n"
" direction: gpio:14\n"
" step: gpio.12\n"
" gang1:\n"
" null_motor:\n"
"\n" "\n"
" y:\n" " y:\n"
" steps_per_mm: 800\n"
" max_rate: 2000\n"
" acceleration: 25\n"
" max_travel: 1000\n"
" home_mpos: 10\n"
"\n"
" gang0:\n"
" endstops:\n"
" dual: gpio.4:high:pd\n"
" stepstick:\n"
" direction: gpio:15\n"
" step: gpio.26\n"
" gang1:\n"
" null_motor:\n"
"\n" "\n"
" z:\n" " z:\n"
" steps_per_mm: 800\n"
" max_rate: 2000\n"
" acceleration: 25\n"
" max_travel: 1000\n"
" home_mpos: 10\n"
"\n"
" gang0:\n"
" endstops:\n"
" dual: gpio.16:pu:low\n"
" stepstick:\n"
" direction: gpio:33\n"
" step: gpio.27\n"
" gang1:\n"
" null_motor:\n"
"\n" "\n"
"\n" "\n"
"coolant:\n" "coolant:\n"
@@ -86,115 +44,113 @@ namespace Configuration {
"\n"; "\n";
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
p.Tokenize();
{ {
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("name"), "Expected 'name'"); Assert(p.key().equals("name"), "Expected 'name'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("board"), "Expected 'board'"); Assert(p.key().equals("board"), "Expected 'board'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("yaml_wiki"), "Expected 'yaml_wiki'"); Assert(p.key().equals("yaml_wiki"), "Expected 'yaml_wiki'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("idle_time"), "Expected 'idle_time'"); Assert(p.key().equals("idle_time"), "Expected 'idle_time'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("step_type"), "Expected 'step_type'"); Assert(p.key().equals("step_type"), "Expected 'step_type'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("dir_delay_microseconds"), "Expected 'dir_delay_microseconds'"); Assert(p.key().equals("dir_delay_microseconds"), "Expected 'dir_delay_microseconds'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("pulse_microseconds"), "Expected 'pulse_microseconds'"); Assert(p.key().equals("pulse_microseconds"), "Expected 'pulse_microseconds'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("disable_delay_us"), "Expected 'disable_delay_us'"); Assert(p.key().equals("disable_delay_us"), "Expected 'disable_delay_us'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("homing_init_lock"), "Expected 'homing_init_lock'"); Assert(p.key().equals("homing_init_lock"), "Expected 'homing_init_lock'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("axes"), "Expected 'axes'"); Assert(p.key().equals("axes"), "Expected 'axes'");
{ {
p.enter(); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("number_axis"), "Expected 'number_axis'"); Assert(p.key().equals("number_axis"), "Expected 'number_axis'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("shared_stepper_disable"), "Expected 'shared_stepper_disable'"); Assert(p.key().equals("shared_stepper_disable"), "Expected 'shared_stepper_disable'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("x"), "Expected 'x'"); Assert(p.key().equals("x"), "Expected 'x'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("y"), "Expected 'y'"); Assert(p.key().equals("y"), "Expected 'y'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("z"), "Expected 'z'"); Assert(p.key().equals("z"), "Expected 'z'");
Assert(!p.moveNext(), "Move next failed.");
Assert(p.isEndSection(), "EOS expected");
p.leave();
} }
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.key().equals("coolant"), "Expected 'coolant'"); Assert(p.key().equals("coolant"), "Expected 'coolant'");
{ {
p.enter(); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("flood"), "Expected 'flood'"); Assert(p.key().equals("flood"), "Expected 'flood'");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("mist"), "Expected 'mist'"); Assert(p.key().equals("mist"), "Expected 'mist'");
Assert(!p.moveNext(), "Move next failed.");
Assert(p.isEndSection(), "No EOS expected");
p.leave();
} }
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.key().equals("comms"), "Expected 'comms'"); Assert(p.key().equals("comms"), "Expected 'comms'");
{ {
p.enter(); p.Tokenize();
Assert(!p.Eof(), "No EOF expected");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("wifi_sta"), "Expected 'wifi_sta'"); Assert(p.key().equals("wifi_sta"), "Expected 'wifi_sta'");
{ {
p.enter(); p.Tokenize();
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("ssid"), "Expected 'ssid'"); Assert(p.key().equals("ssid"), "Expected 'ssid'");
Assert(!p.moveNext(), "Move next failed.");
Assert(p.isEndSection(), "No EOS expected");
p.leave();
} }
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.key().equals("wifi_ap"), "Expected 'wifi_ap'"); Assert(p.key().equals("wifi_ap"), "Expected 'wifi_ap'");
Assert(!p.moveNext(), "Move next failed."); {
Assert(p.isEndSection(), "EOS expected"); p.Tokenize();
Assert(!p.Eof(), "No EOF expected");
p.leave(); Assert(p.key().equals("ip_address"), "Expected 'ip_address'");
p.Tokenize();
Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("ssid"), "Expected 'ssid'");
}
} }
Assert(!p.isEndSection(), "No EOS expected"); Assert(!p.Eof(), "No EOF expected");
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.key().equals("probe"), "Expected 'probe'"); Assert(p.key().equals("probe"), "Expected 'probe'");
Assert(!p.moveNext(), "Move next failed."); {
Assert(p.isEndSection(), "EOS expected"); p.Tokenize();
Assert(!p.Eof(), "No EOF expected");
Assert(p.key().equals("pin"), "Expected 'pin'");
}
p.Tokenize();
Assert(p.Eof(), "No EOF expected");
} }
} }
} }

View File

@@ -8,26 +8,28 @@ namespace Configuration {
const char* config = "a: aap\n" const char* config = "a: aap\n"
"b: banaan\n" "b: banaan\n"
"\n" "\n"
"c: chocolade"; "c: chocolade\n";
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
p.Tokenize();
{ {
Assert(p.key().equals("a"), "Expected 'a'"); Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'"); Assert(p.stringValue().equals("aap"), "Expected 'aap'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("b"), "Expected 'b'"); Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'"); Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("c"), "Expected 'c'"); Assert(p.key().equals("c"), "Expected 'c'");
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'"); Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
} }
Assert(!p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.Eof(), "EOF failed.");
} }
Test(YamlParser, SimpleSection) { Test(YamlParser, SimpleSection) {
@@ -35,33 +37,32 @@ namespace Configuration {
"s:\n" "s:\n"
" b: banaan\n" " b: banaan\n"
"\n" "\n"
"c: chocolade"; "c: chocolade\n";
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
p.Tokenize();
{ {
Assert(p.key().equals("a"), "Expected 'a'"); Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'"); Assert(p.stringValue().equals("aap"), "Expected 'aap'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("s"), "Expected 's'"); Assert(p.key().equals("s"), "Expected 's'");
p.enter();
{ {
p.Tokenize();
Assert(p.key().equals("b"), "Expected 'b'"); Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'"); Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("c"), "Expected 'c'"); Assert(p.key().equals("c"), "Expected 'c'");
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'"); Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
} }
Assert(!p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.Eof(), "EOF failed.");
} }
Test(YamlParser, TwoSequentialSections) { Test(YamlParser, TwoSequentialSections) {
@@ -71,129 +72,42 @@ namespace Configuration {
"t:\n" "t:\n"
" c: chocolade\n" " c: chocolade\n"
"\n" "\n"
"w: wipwap"; "w: wipwap\n";
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
p.Tokenize();
{ {
Assert(p.key().equals("a"), "Expected 'a'"); Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'"); Assert(p.stringValue().equals("aap"), "Expected 'aap'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("s"), "Expected 's'"); Assert(p.key().equals("s"), "Expected 's'");
p.enter(); p.Tokenize();
{ {
Assert(p.key().equals("b"), "Expected 'b'"); Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'"); Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("t"), "Expected 't'"); Assert(p.key().equals("t"), "Expected 't'");
p.enter(); p.Tokenize();
{ {
Assert(p.key().equals("c"), "Expected 'c'"); Assert(p.key().equals("c"), "Expected 'c'");
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'"); Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("w"), "Expected 'w'"); Assert(p.key().equals("w"), "Expected 'w'");
Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'"); Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'");
} }
Assert(!p.moveNext(), "Move next failed."); p.Tokenize();
} Assert(p.Eof(), "EOF failed.");
Test(YamlParser, TwoSequentialSectionsSkipFirst) {
const char* config = "a: aap\n"
"s:\n"
" b: banaan\n"
"t:\n"
" c: chocolade\n"
"\n"
"w: wipwap";
Parser p(config, config + strlen(config));
{
Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("s"), "Expected 's'");
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("t"), "Expected 't'");
p.enter();
{
Assert(p.key().equals("c"), "Expected 'c'");
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
}
Assert(!p.moveNext(), "Move next failed.");
p.leave();
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("w"), "Expected 'w'");
Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'");
}
Assert(!p.moveNext(), "Move next failed.");
}
Test(YamlParser, TwoSequentialSectionsSkipSecond) {
const char* config = "a: aap\n"
"s:\n"
" b: banaan\n"
"t:\n"
" c: chocolade\n"
"\n"
"w: wipwap";
Parser p(config, config + strlen(config));
{
Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("s"), "Expected 's'");
p.enter();
{
Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
}
Assert(!p.moveNext(), "Move next failed.");
p.leave();
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("t"), "Expected 't'");
}
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("w"), "Expected 'w'");
Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'");
}
Assert(!p.moveNext(), "Move next failed.");
} }
Test(YamlParser, TwoSequentialSectionsInASection) { Test(YamlParser, TwoSequentialSectionsInASection) {
@@ -206,62 +120,56 @@ namespace Configuration {
" c: chocolade\n" " c: chocolade\n"
" e: eventjes\n" " e: eventjes\n"
"\n" "\n"
"w: wipwap"; "w: wipwap\n";
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
p.Tokenize();
{ {
Assert(p.key().equals("a"), "Expected 'a'"); Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'"); Assert(p.stringValue().equals("aap"), "Expected 'aap'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("r"), "Expected 'r'"); Assert(p.key().equals("r"), "Expected 'r'");
p.enter(); p.Tokenize();
{ {
Assert(p.key().equals("s"), "Expected 's'"); Assert(p.key().equals("s"), "Expected 's'");
p.enter(); p.Tokenize();
{ {
Assert(p.key().equals("b"), "Expected 'b'"); Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'"); Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("d"), "Expected 'd'"); Assert(p.key().equals("d"), "Expected 'd'");
Assert(p.stringValue().equals("dinges"), "Expected 'dinges'"); Assert(p.stringValue().equals("dinges"), "Expected 'dinges'");
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("t"), "Expected 't'"); Assert(p.key().equals("t"), "Expected 't'");
p.enter(); p.Tokenize();
{ {
Assert(p.key().equals("c"), "Expected 'c'"); Assert(p.key().equals("c"), "Expected 'c'");
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'"); Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("e"), "Expected 'e'"); Assert(p.key().equals("e"), "Expected 'e'");
Assert(p.stringValue().equals("eventjes"), "Expected 'eventjes'"); Assert(p.stringValue().equals("eventjes"), "Expected 'eventjes'");
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(!p.moveNext(), "Move next failed.");
p.leave();
} }
Assert(p.moveNext(), "Move next failed."); p.Tokenize();
{ {
Assert(p.key().equals("w"), "Expected 'w'"); Assert(p.key().equals("w"), "Expected 'w'");
Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'"); Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'");
} }
Assert(!p.moveNext(), "Move next failed."); p.Tokenize();
Assert(p.Eof(), "EOF failed.");
} }
} }

View File

@@ -52,10 +52,10 @@ namespace Configuration {
int banaan; int banaan;
void validate() const {} void validate() const {}
void handle(HandlerBase& handler) { void group(HandlerBase& handler) override {
handler.handle("aap", aap); handler.item("aap", aap);
handler.handle("type", value, stepTypes); handler.item("type", value, stepTypes);
handler.handle("banaan", banaan); handler.item("banaan", banaan);
} }
}; };
@@ -66,9 +66,9 @@ namespace Configuration {
int foo = 0; int foo = 0;
void validate() const {} void validate() const {}
void group(HandlerBase& handler) { void group(HandlerBase& handler) override {
handler.item("n1", n1); handler.section("n1", n1);
handler.item("n2", n2); handler.section("n2", n2);
handler.item("foo", foo); handler.item("foo", foo);
} }
}; };
@@ -79,10 +79,11 @@ namespace Configuration {
Parser p(config, config + strlen(config)); Parser p(config, config + strlen(config));
ParserHandler handler(p); ParserHandler handler(p);
test.group(handler); handler.enterSection("machine", &test);
for (; !p.isEndSection(); handler.moveNext()) { // test.group(handler);
test.group(handler); // for (; !p.Eof(); handler.moveNext()) {
} // test.group(handler);
// }
} }
}; };
@@ -90,7 +91,7 @@ namespace Configuration {
const char* config = "a: aap\n" const char* config = "a: aap\n"
"b: banaan\n" "b: banaan\n"
"\n" "\n"
"c: chocolade"; "c: chocolade\n";
TestBasic test; TestBasic test;
Helper::Parse(config, test); Helper::Parse(config, test);