62b301
From d829e7163f6a98547cef3b0106a6a98728275065 Mon Sep 17 00:00:00 2001
62b301
From: Yu Watanabe <watanabe.yu+github@gmail.com>
62b301
Date: Tue, 11 Sep 2018 13:35:27 +0900
62b301
Subject: [PATCH] test: add tests for strv_join_prefix()
62b301
62b301
(cherry picked from commit 474a595af7544a670de70e1eb873bcee1bb00044)
62b301
62b301
Related: #2049788
62b301
---
62b301
 src/test/test-strv.c | 33 +++++++++++++++++++++++++++++++++
62b301
 1 file changed, 33 insertions(+)
62b301
62b301
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
62b301
index 79d999d3ed..9e7d98500f 100644
62b301
--- a/src/test/test-strv.c
62b301
+++ b/src/test/test-strv.c
62b301
@@ -158,6 +158,38 @@ static void test_strv_join(void) {
62b301
         assert_se(streq(w, ""));
62b301
 }
62b301
 
62b301
+static void test_strv_join_prefix(void) {
62b301
+        _cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL, *v = NULL, *w = NULL;
62b301
+
62b301
+        p = strv_join_prefix((char **)input_table_multiple, ", ", "foo");
62b301
+        assert_se(p);
62b301
+        assert_se(streq(p, "fooone, footwo, foothree"));
62b301
+
62b301
+        q = strv_join_prefix((char **)input_table_multiple, ";", "foo");
62b301
+        assert_se(q);
62b301
+        assert_se(streq(q, "fooone;footwo;foothree"));
62b301
+
62b301
+        r = strv_join_prefix((char **)input_table_multiple, NULL, "foo");
62b301
+        assert_se(r);
62b301
+        assert_se(streq(r, "fooone footwo foothree"));
62b301
+
62b301
+        s = strv_join_prefix((char **)input_table_one, ", ", "foo");
62b301
+        assert_se(s);
62b301
+        assert_se(streq(s, "fooone"));
62b301
+
62b301
+        t = strv_join_prefix((char **)input_table_none, ", ", "foo");
62b301
+        assert_se(t);
62b301
+        assert_se(streq(t, ""));
62b301
+
62b301
+        v = strv_join_prefix((char **)input_table_two_empties, ", ", "foo");
62b301
+        assert_se(v);
62b301
+        assert_se(streq(v, "foo, foo"));
62b301
+
62b301
+        w = strv_join_prefix((char **)input_table_one_empty, ", ", "foo");
62b301
+        assert_se(w);
62b301
+        assert_se(streq(w, "foo"));
62b301
+}
62b301
+
62b301
 static void test_strv_unquote(const char *quoted, char **list) {
62b301
         _cleanup_strv_free_ char **s;
62b301
         _cleanup_free_ char *j;
62b301
@@ -722,6 +754,7 @@ int main(int argc, char *argv[]) {
62b301
         test_strv_find_prefix();
62b301
         test_strv_find_startswith();
62b301
         test_strv_join();
62b301
+        test_strv_join_prefix();
62b301
 
62b301
         test_strv_unquote("    foo=bar     \"waldo\"    zzz    ", STRV_MAKE("foo=bar", "waldo", "zzz"));
62b301
         test_strv_unquote("", STRV_MAKE_EMPTY);