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