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

Added some yaml parser tests

This commit is contained in:
Stefan de Bruijn
2021-06-04 22:02:33 +02:00
parent d79b3b29e2
commit 12f0863c4c
4 changed files with 424 additions and 11 deletions

View File

@@ -0,0 +1,200 @@
#include "../TestFramework.h"
#include <src/Configuration/Tokenizer.h>
#include <src/Configuration/Parser.h>
namespace Configuration {
Test(YamlComplete, Test) {
const char* config = "name: \"ESP32 Dev Controller V4\"\n"
"board: \"ESP32 Dev Controller V4\"\n"
"yaml_wiki: \"https://github.com/bdring/Grbl_Esp32/wiki/YAML-Config-File\"\n"
"\n"
"idle_time: 250\n"
"step_type: rmt\n"
"dir_delay_microseconds: 1\n"
"pulse_microseconds: 2\n"
"disable_delay_us: 0\n"
"homing_init_lock: false\n"
"\n"
"axes:\n"
" number_axis: 3\n"
" shared_stepper_disable: gpio.13:low\n"
" \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"
" 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"
" 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"
"coolant:\n"
" flood: gpio.25:low\n"
" mist: gpio.21\n"
"\n"
"comms:\n"
" wifi_sta:\n"
" ssid: StefanMieke\n"
"\n"
" wifi_ap:\n"
" ip_address: \"192.168.0.1\"\n"
" ssid: ScratchThat\n"
" \n"
"probe:\n"
" pin: gpio.32:high:pu\n"
"\n";
Parser p(config, config + strlen(config));
{
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("name"), "Expected 'name'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("board"), "Expected 'board'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("yaml_wiki"), "Expected 'yaml_wiki'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("idle_time"), "Expected 'idle_time'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("step_type"), "Expected 'step_type'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("dir_delay_microseconds"), "Expected 'dir_delay_microseconds'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("pulse_microseconds"), "Expected 'pulse_microseconds'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("disable_delay_us"), "Expected 'disable_delay_us'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("homing_init_lock"), "Expected 'homing_init_lock'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("axes"), "Expected 'axes'");
{
p.enter();
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("number_axis"), "Expected 'number_axis'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("shared_stepper_disable"), "Expected 'shared_stepper_disable'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("x"), "Expected 'x'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("y"), "Expected 'y'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
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.moveNext(), "Move next failed.");
Assert(p.key().equals("coolant"), "Expected 'coolant'");
{
p.enter();
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("flood"), "Expected 'flood'");
Assert(p.moveNext(), "Move next failed.");
Assert(!p.isEndSection(), "No EOS expected");
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.moveNext(), "Move next failed.");
Assert(p.key().equals("comms"), "Expected 'comms'");
{
p.enter();
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.key().equals("wifi_sta"), "Expected 'wifi_sta'");
{
p.enter();
Assert(!p.isEndSection(), "No EOS expected");
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.moveNext(), "Move next failed.");
Assert(p.key().equals("wifi_ap"), "Expected 'wifi_ap'");
Assert(!p.moveNext(), "Move next failed.");
Assert(p.isEndSection(), "EOS expected");
p.leave();
}
Assert(!p.isEndSection(), "No EOS expected");
Assert(p.moveNext(), "Move next failed.");
Assert(p.key().equals("probe"), "Expected 'probe'");
Assert(!p.moveNext(), "Move next failed.");
Assert(p.isEndSection(), "EOS expected");
}
}
}

View File

@@ -5,13 +5,12 @@
namespace Configuration {
Test(YamlParser, BasicProperties) {
const char* config =
"a: aap\n"
"b: banaan\n"
"\n"
"c: chocolade";
const char* config = "a: aap\n"
"b: banaan\n"
"\n"
"c: chocolade";
Parser p(config, config + strlen(config));
Parser p(config, config + strlen(config));
{
Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
@@ -31,9 +30,14 @@ namespace Configuration {
Assert(!p.moveNext(), "Move next failed.");
}
Test(YamlParser, SimpleSection) {
const char* config = "a: aap\nb: banaan\n\nc: chocolade";
Parser p(config, config + strlen(config));
Test(YamlParser, SimpleSection) {
const char* config = "a: aap\n"
"s:\n"
" b: banaan\n"
"\n"
"c: chocolade";
Parser p(config, config + strlen(config));
{
Assert(p.key().equals("a"), "Expected 'a'");
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
@@ -41,8 +45,15 @@ namespace Configuration {
Assert(p.moveNext(), "Move next failed.");
{
Assert(p.key().equals("b"), "Expected 'b'");
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
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.");
@@ -53,4 +64,204 @@ namespace Configuration {
Assert(!p.moveNext(), "Move next failed.");
}
Test(YamlParser, TwoSequentialSections) {
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'");
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, 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) {
const char* config = "a: aap\n"
"r:\n"
" s:\n"
" b: banaan\n"
" d: dinges\n"
" t:\n"
" c: chocolade\n"
" e: eventjes\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("r"), "Expected 'r'");
p.enter();
{
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.");
{
Assert(p.key().equals("d"), "Expected 'd'");
Assert(p.stringValue().equals("dinges"), "Expected 'dinges'");
}
Assert(!p.moveNext(), "Move next failed.");
p.leave();
}
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.");
{
Assert(p.key().equals("e"), "Expected 'e'");
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.");
{
Assert(p.key().equals("w"), "Expected 'w'");
Assert(p.stringValue().equals("wipwap"), "Expected 'wipwap'");
}
Assert(!p.moveNext(), "Move next failed.");
}
}

View File

@@ -76,6 +76,7 @@
<ClCompile Include="Grbl_Esp32\src\Pins\VoidPinDetail.cpp" />
<ClCompile Include="Grbl_Esp32\src\StackTrace\AssertionFailed.cpp" />
<ClCompile Include="Grbl_Esp32\src\StackTrace\debug_helpers.cpp" />
<ClCompile Include="Grbl_Esp32\test\Configuration\YamlComplete.cpp" />
<ClCompile Include="Grbl_Esp32\test\Configuration\YamlParser.cpp" />
<ClCompile Include="Grbl_Esp32\test\Pins\BasicGPIO.cpp" />
<ClCompile Include="Grbl_Esp32\test\Pins\Error.cpp" />

View File

@@ -170,6 +170,7 @@
<ClCompile Include="Grbl_Esp32\src\Configuration\Parser.cpp">
<Filter>src\Configuration</Filter>
</ClCompile>
<ClCompile Include="Grbl_Esp32\test\Configuration\YamlComplete.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="Grbl_Esp32\test\UnitTests.md">