summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-02-05 14:36:16 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-02-12 14:31:50 +1000
commite6ed506df335e8eb0d79d22d22d0734a2b93fe43 (patch)
tree7ad530110cfb98dc731a9aeb4961b26a48c2b14f /test
parent8ab2581d202e95f51dabc84eebd7e0311b59bfe1 (diff)
downloadlibinput-e6ed506df335e8eb0d79d22d22d0734a2b93fe43.tar.gz
utils: add a trunkname() function to extract the trunk of a filename
/path/to/foo.bar returns "foo" Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r--test/test-utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test-utils.c b/test/test-utils.c
index 8cc3f22a..f31b2e07 100644
--- a/test/test-utils.c
+++ b/test/test-utils.c
@@ -1292,6 +1292,32 @@ START_TEST(strneq_test)
}
END_TEST
+START_TEST(trunkname_test)
+{
+ struct test {
+ const char *path;
+ const char *expected;
+ } tests[] = {
+ { "foo.c", "foo" },
+ { "/path/to/foo.h", "foo" },
+ { "../bar.foo", "bar" },
+ { "./bar.foo.baz", "bar.foo" },
+ { "./", "" },
+ { "/", "" },
+ { "/bar/", "" },
+ { "/bar", "bar" },
+ { "", "" },
+ };
+ struct test *t;
+
+ ARRAY_FOR_EACH(tests, t) {
+ char *result = trunkname(t->path);
+ ck_assert_str_eq(result, t->expected);
+ free(result);
+ }
+}
+END_TEST
+
static Suite *
litest_utils_suite(void)
{
@@ -1335,6 +1361,7 @@ litest_utils_suite(void)
tcase_add_test(tc, strverscmp_test);
tcase_add_test(tc, streq_test);
tcase_add_test(tc, strneq_test);
+ tcase_add_test(tc, trunkname_test);
suite_add_tcase(s, tc);