Fix issue with printing longHelp
Corrected a bug where the parser misinterpreted `help cd` as an invalid
command, expecting `helpcd`. This problem was caused by an issue within
the help grammar rules.
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/234
Change-Id: I3494f99013d1b119ce255ab68faf448b4bc25b1f
diff --git a/tests/command_completion.cpp b/tests/command_completion.cpp
index 7aafd02..48daa9c 100644
--- a/tests/command_completion.cpp
+++ b/tests/command_completion.cpp
@@ -90,5 +90,20 @@
expectedContextLength = 0;
}
+ SECTION("help - add space")
+ {
+ input = "help";
+ expectedCompletions = {"help "};
+ expectedContextLength = 4;
+ }
+
+ SECTION("help - list commands")
+ {
+ input = "help ";
+ expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move", "dump", "prepare", "exec", "cancel", "switch", "quit"};
+ expectedContextLength = 0;
+ }
+
+
REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
}
diff --git a/tests/misc_commands.cpp b/tests/misc_commands.cpp
index 868189d..ae36808 100644
--- a/tests/misc_commands.cpp
+++ b/tests/misc_commands.cpp
@@ -38,4 +38,31 @@
}
REQUIRE(boost::get<switch_>(parser.parseCommand(input, errorStream)) == expected);
}
+
+ SECTION("help")
+ {
+ std::string input;
+ bool expectedCommand = false;
+ SECTION("Short help")
+ {
+ input = "help";
+ }
+ SECTION("Short help with trailing whitespace")
+ {
+ input = "help ";
+ }
+ SECTION("Long help")
+ {
+ input = "help cd";
+ expectedCommand = true;
+ }
+ SECTION("Long help with trailing whitespace")
+ {
+ input = "help cd ";
+ expectedCommand = true;
+ }
+
+ auto result = boost::get<help_>(parser.parseCommand(input, errorStream));
+ REQUIRE(!!result.m_cmd == expectedCommand);
+ }
}