Fix `switch` parsing
There are actually two fixes: the first one is a direct fix to the
linked issue. The attribute of the rule for switch was wrong. I'm not
sure how I missed that, but OK, now we have tests.
The other bug:
For some reason, the completion generator prevented the symbol table
parser from running and the value inside the resulting switch_ was
undefined. Asserting the attribute of the completion generator seems to
solve the issue.
I thought this would have something to do with the fact that I'm using
single member fusion structs. However, the bug still persisted even when
converting them into non-fusion structs (as suggested in the first
issue).
At some point, all single-member fusion structs should be converted into
non-fusion structs, but because it doesn't solve my problem, I won't be
doing it now.
Issue: https://github.com/boostorg/spirit/issues/463
Issue: https://github.com/boostorg/spirit/issues/659
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/218
Change-Id: I364b32b76741c198808cc2b3c5027913162d0703
diff --git a/tests/misc_commands.cpp b/tests/misc_commands.cpp
new file mode 100644
index 0000000..868189d
--- /dev/null
+++ b/tests/misc_commands.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Václav Kubernát <kubervac@cesnet.cz>
+ *
+*/
+
+#include "trompeloeil_doctest.hpp"
+#include "parser.hpp"
+#include "pretty_printers.hpp"
+#include "static_schema.hpp"
+
+TEST_CASE("miscellaneous commands")
+{
+ auto schema = std::make_shared<StaticSchema>();
+ Parser parser(schema);
+ std::ostringstream errorStream;
+ SECTION("switch")
+ {
+ std::string input;
+ switch_ expected;
+ SECTION("operational")
+ {
+ expected.m_target = DatastoreTarget::Operational;
+ input = "switch operational";
+ }
+
+ SECTION("running")
+ {
+ expected.m_target = DatastoreTarget::Running;
+ input = "switch running";
+ }
+
+ SECTION("startup")
+ {
+ expected.m_target = DatastoreTarget::Startup;
+ input = "switch startup";
+ }
+ REQUIRE(boost::get<switch_>(parser.parseCommand(input, errorStream)) == expected);
+ }
+}