From aee3d639b5096349413021537ae842c8c33ef6cf Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 14 Mar 2024 17:44:43 -0700 Subject: Move `shell_words` into its own file Change-Id: I34c0ebfb6dcea49bf632d8880e04075335a132bf --- tests/unit/libutil/shlex.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/unit/libutil/shlex.cc (limited to 'tests') 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 +#include +#include + +using testing::Eq; + +namespace nix { + +TEST(Shlex, shell_split) { + ASSERT_THAT(shell_split(""), Eq>({})); + ASSERT_THAT(shell_split(" "), Eq>({})); + + ASSERT_THAT( + shell_split("puppy doggy"), + Eq>({ + "puppy", + "doggy", + }) + ); + + ASSERT_THAT( + shell_split("goldie \"puppy 'doggy'\" sweety"), + Eq>({ + "goldie", + "puppy 'doggy'", + "sweety", + }) + ); + + ASSERT_THAT( + shell_split("\"pupp\\\"y\""), + Eq>({ "pupp\"y" }) + ); + + ASSERT_THAT( + shell_split("goldie 'puppy' doggy"), + Eq>({ + "goldie", + "puppy", + "doggy", + }) + ); + + ASSERT_THAT( + shell_split("'pupp\\\"y'"), + Eq>({ + "pupp\\\"y", + }) + ); + + ASSERT_THROW(shell_split("\"puppy"), ShlexError); + ASSERT_THROW(shell_split("'puppy"), ShlexError); +} + +} // namespace nix -- cgit v1.2.3