summaryrefslogtreecommitdiff
path: root/test/test-paths.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-paths.cc')
-rw-r--r--test/test-paths.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/test-paths.cc b/test/test-paths.cc
new file mode 100644
index 0000000..c049165
--- /dev/null
+++ b/test/test-paths.cc
@@ -0,0 +1,55 @@
+// -*- mode: c++; c-basic-offset: 2; -*-
+
+#include "common.hh"
+#include "test.hh"
+
+#include "strings.hh"
+
+namespace {
+
+bool test_trim(char const* expected, char const* input) {
+ ASSERT_EQ(expected, Strings::trim(input));
+ return true;
+}
+
+bool test_quote(char const* expected, char const* input) {
+ ASSERT_EQ(expected, Strings::quote(input));
+ return true;
+}
+
+bool test_unquote(char const* expected, char const* input) {
+ ASSERT_EQ(expected, Strings::unquote(input));
+ return true;
+}
+
+} // namespace
+
+int main(void) {
+ BEFORE;
+ RUN(test_trim("", ""));
+ RUN(test_trim("foo", "foo"));
+ RUN(test_trim("foo", " foo"));
+ RUN(test_trim("foo", " foo "));
+ RUN(test_trim("foo", " foo "));
+ RUN(test_trim("", " "));
+ RUN(test_trim("", " "));
+ RUN(test_trim("foo bar", "foo bar"));
+ RUN(test_trim("foo bar", " foo bar "));
+ RUN(test_quote("\"\"", ""));
+ RUN(test_quote("\"'\"", "'"));
+ RUN(test_quote("\"\\\"\"", "\""));
+ RUN(test_quote("\"\\\\\"", "\\"));
+ RUN(test_quote("\"foo\"", "foo"));
+ RUN(test_quote("\"\\\"fo\\\"o\"", "\"fo\"o"));
+ RUN(test_quote("\"f\\\"o\\\"o\"", "f\"o\"o"));
+ RUN(test_quote("\"\\\"foo\\\"\"", "\"foo\""));
+ RUN(test_unquote("", "\"\""));
+ RUN(test_unquote("'", "\"'\""));
+ RUN(test_unquote("\"", "\"\\\"\""));
+ RUN(test_unquote("\\", "\"\\\\\""));
+ RUN(test_unquote("foo", "\"foo\""));
+ RUN(test_unquote("\"fo\"o", "\"\\\"fo\\\"o\""));
+ RUN(test_unquote("f\"o\"o", "\"f\\\"o\\\"o\""));
+ RUN(test_unquote("\"foo\"", "\"\\\"foo\\\"\""));
+ AFTER;
+}