aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorwiggles dog <rbt@sent.as>2024-03-28 22:49:00 +0000
committerGerrit Code Review <gerrit@lix>2024-03-28 22:49:00 +0000
commit62332c12505adc033eca7355de2b8a469355664f (patch)
treefd52cac8b68ba1ed1c6e2a45ee4b6608139dc26f /tests
parent81e50fef70c2526f560439fde6dee8d33f961948 (diff)
parentaee3d639b5096349413021537ae842c8c33ef6cf (diff)
Merge "Move `shell_words` into its own file" into main
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/libutil/shlex.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/unit/libutil/shlex.cc b/tests/unit/libutil/shlex.cc
new file mode 100644
index 000000000..2a13635f0
--- /dev/null
+++ b/tests/unit/libutil/shlex.cc
@@ -0,0 +1,57 @@
+#include "shlex.hh"
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <sstream>
+
+using testing::Eq;
+
+namespace nix {
+
+TEST(Shlex, shell_split) {
+ ASSERT_THAT(shell_split(""), Eq<std::vector<std::string>>({}));
+ ASSERT_THAT(shell_split(" "), Eq<std::vector<std::string>>({}));
+
+ ASSERT_THAT(
+ shell_split("puppy doggy"),
+ Eq<std::vector<std::string>>({
+ "puppy",
+ "doggy",
+ })
+ );
+
+ ASSERT_THAT(
+ shell_split("goldie \"puppy 'doggy'\" sweety"),
+ Eq<std::vector<std::string>>({
+ "goldie",
+ "puppy 'doggy'",
+ "sweety",
+ })
+ );
+
+ ASSERT_THAT(
+ shell_split("\"pupp\\\"y\""),
+ Eq<std::vector<std::string>>({ "pupp\"y" })
+ );
+
+ ASSERT_THAT(
+ shell_split("goldie 'puppy' doggy"),
+ Eq<std::vector<std::string>>({
+ "goldie",
+ "puppy",
+ "doggy",
+ })
+ );
+
+ ASSERT_THAT(
+ shell_split("'pupp\\\"y'"),
+ Eq<std::vector<std::string>>({
+ "pupp\\\"y",
+ })
+ );
+
+ ASSERT_THROW(shell_split("\"puppy"), ShlexError);
+ ASSERT_THROW(shell_split("'puppy"), ShlexError);
+}
+
+} // namespace nix