summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2015-06-23 17:00:40 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2015-08-07 15:50:42 +0000
commit206644aedeb8859801051ac170ec562c6a113a79 (patch)
tree88ba118333423abc16871dc490a74cd911218b3d /src/test
parent12ba2c44dde4d7cfc0e531dbc3cbd0581c323637 (diff)
util: Allow non-separator coalescing parsing in extract_first_word
If EXTRACT_DONT_COALESCE_SEPARATORS is passed, then leading separators, trailing separators and spans of multiple separators aren't skipped, and empty arguments from before, after or between separators may be extracted.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-util.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 40f5d34de3..fc7a3de106 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1744,6 +1744,38 @@ static void test_extract_first_word(void) {
assert_se(streq(t, ""));
free(t);
assert_se(isempty(p));
+
+ p = original = ":foo\\:bar::waldo:";
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
+ assert_se(t);
+ assert_se(streq(t, ""));
+ free(t);
+ assert_se(p == original + 1);
+
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
+ assert_se(streq(t, "foo:bar"));
+ free(t);
+ assert_se(p == original + 10);
+
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
+ assert_se(t);
+ assert_se(streq(t, ""));
+ free(t);
+ assert_se(p == original + 11);
+
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
+ assert_se(streq(t, "waldo"));
+ free(t);
+ assert_se(p == original + 17);
+
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
+ assert_se(streq(t, ""));
+ free(t);
+ assert_se(p == NULL);
+
+ assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 0);
+ assert_se(!t);
+ assert_se(!p);
}
static void test_extract_first_word_and_warn(void) {