summaryrefslogtreecommitdiff
path: root/src/test/test-strv.c
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2015-06-19 15:24:34 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2015-08-07 15:50:43 +0000
commit8adaf7bd23baa6e2cd99e9e88e55d0f5f5db29a2 (patch)
tree708a0dd3995411d49cee3174f340986b9e5587c5 /src/test/test-strv.c
parentffcd3e89d55c870c94aa15ee94dab3e029a586cf (diff)
strv: convert strv_split_quotes into a generic strv_split_extract
strv_split_extract is to strv_split_quotes as extract_first_word was to unquote_first_word. Now there's extract_first_word for extracting a single argument, extract_many_words for extracting a bounded number of arguments, and strv_split_extract for extracting an arbitrary number of arguments.
Diffstat (limited to 'src/test/test-strv.c')
-rw-r--r--src/test/test-strv.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 6e3c81395c..53074b4b65 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -165,7 +165,7 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted
assert_se(p);
assert_se(streq(p, quoted));
- r = strv_split_quoted(&s, quoted, 0);
+ r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
assert_se(r == 0);
assert_se(s);
STRV_FOREACH(t, s) {
@@ -182,7 +182,7 @@ static void test_strv_unquote(const char *quoted, char **list) {
char **t;
int r;
- r = strv_split_quoted(&s, quoted, 0);
+ r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
assert_se(r == 0);
assert_se(s);
j = strv_join(s, " | ");
@@ -199,7 +199,7 @@ static void test_invalid_unquote(const char *quoted) {
char **s = NULL;
int r;
- r = strv_split_quoted(&s, quoted, 0);
+ r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
assert_se(s == NULL);
assert_se(r == -EINVAL);
}
@@ -219,6 +219,21 @@ static void test_strv_split(void) {
}
}
+static void test_strv_split_extract(void) {
+ _cleanup_strv_free_ char **l = NULL;
+ const char *str = ":foo\\:bar::waldo:";
+ int r;
+
+ r = strv_split_extract(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
+ assert_se(r == 0);
+ assert_se(streq_ptr(l[0], ""));
+ assert_se(streq_ptr(l[1], "foo:bar"));
+ assert_se(streq_ptr(l[2], ""));
+ assert_se(streq_ptr(l[3], "waldo"));
+ assert_se(streq_ptr(l[4], ""));
+ assert_se(streq_ptr(l[5], NULL));
+}
+
static void test_strv_split_newlines(void) {
unsigned i = 0;
char **s;
@@ -583,6 +598,7 @@ int main(int argc, char *argv[]) {
test_invalid_unquote("'x'y'g");
test_strv_split();
+ test_strv_split_extract();
test_strv_split_newlines();
test_strv_split_nulstr();
test_strv_parse_nulstr();