fix some invalid inputs
Change-Id: I9302c52d7ed0142eb1b867ace101b41d41b05e2d
diff --git a/src/grammars.hpp b/src/grammars.hpp
index 45a901f..c6f3ab5 100644
--- a/src/grammars.hpp
+++ b/src/grammars.hpp
@@ -32,8 +32,9 @@
auto const listPrefix_def =
identifier >> '[';
+// even though we don't allow no keys to be supplied, the star allows me to check which keys are missing
auto const listSuffix_def =
- +keyValue > ']';
+ *keyValue > ']';
auto const listElement_def =
listPrefix > listSuffix;
@@ -45,7 +46,7 @@
(container | listElement) % '/';
auto const cd_def =
- lit("cd") > path >> x3::eoi;
+ lit("cd") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
BOOST_SPIRIT_DEFINE(keyValue)
BOOST_SPIRIT_DEFINE(identifier)
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 9c73c61..d6079fb 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -91,11 +91,39 @@
}
}
+
+ SECTION("whitespace handling")
+ {
+ SECTION(" cd a ")
+ {
+ input = " cd a ";
+ expected.m_path.m_nodes.push_back(container_("a"));
+ }
+ }
+
cd_ command = parser.parseCommand(input, errorStream);
REQUIRE(command == expected);
}
SECTION("invalid input")
{
+ SECTION("missing space between a command and its arguments")
+ {
+ SECTION("cda")
+ {
+ input = "cda";
+ }
+ }
+ SECTION("garbage arguments handling")
+ {
+ SECTION("cd a garbage")
+ {
+ input = "cd a garbage";
+ }
+ SECTION("cd a/a2 garbage")
+ {
+ input = "cd a/a2 garbage";
+ }
+ }
SECTION("invalid identifiers")
{
SECTION("nonexistent")
@@ -108,8 +136,19 @@
input = "cd nonexistent/lol";
}
}
+
SECTION("invalid list key identifiers")
{
+ SECTION("list")
+ {
+ input = "cd list";
+ }
+
+ SECTION("list[]")
+ {
+ input = "cd list[]";
+ }
+
SECTION("twoKeyList[invalidKey=4]")
{
input = "cd twoKeyList[invalidKey=4]";