diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-11-23 16:27:15 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-11-26 14:06:01 +0100 |
commit | 52f1552073047195d51901f7e5a5a4fa3189034e (patch) | |
tree | f49a11b7b2dc534829c483e48b95809efd86b04e /src/test | |
parent | update TODO (diff) | |
download | systemd-52f1552073047195d51901f7e5a5a4fa3189034e.tar.xz systemd-52f1552073047195d51901f7e5a5a4fa3189034e.zip |
strv: add new macro STARTSWITH_SET()
This is to startswith() what PATH_STARTSWITH_SET() is to
path_startswith().
Or in other words, checks if the specified string has any of the listed
prefixes, and if so, returns the remainder of the string.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-strv.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 63757afdce..31ef1abb44 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -56,6 +56,20 @@ static void test_strptr_in_set(void) { assert_se(!STRPTR_IN_SET(NULL, NULL)); } +static void test_startswith_set(void) { + assert_se(!STARTSWITH_SET("foo", "bar", "baz", "waldo")); + assert_se(!STARTSWITH_SET("foo", "bar")); + + assert_se(STARTSWITH_SET("abc", "a", "ab", "abc")); + assert_se(STARTSWITH_SET("abc", "ax", "ab", "abc")); + assert_se(STARTSWITH_SET("abc", "ax", "abx", "abc")); + assert_se(!STARTSWITH_SET("abc", "ax", "abx", "abcx")); + + assert_se(streq_ptr(STARTSWITH_SET("foobar", "hhh", "kkk", "foo", "zzz"), "bar")); + assert_se(streq_ptr(STARTSWITH_SET("foobar", "hhh", "kkk", "", "zzz"), "foobar")); + assert_se(streq_ptr(STARTSWITH_SET("", "hhh", "kkk", "zzz", ""), "")); +} + static const char* const input_table_multiple[] = { "one", "two", @@ -847,6 +861,7 @@ int main(int argc, char *argv[]) { test_specifier_printf(); test_str_in_set(); test_strptr_in_set(); + test_startswith_set(); test_strv_foreach(); test_strv_foreach_backwards(); test_strv_foreach_pair(); |