aboutsummaryrefslogtreecommitdiff
path: root/tests/test_completion_path.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_completion_path.c')
-rw-r--r--tests/test_completion_path.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_completion_path.c b/tests/test_completion_path.c
new file mode 100644
index 0000000..8170ee9
--- /dev/null
+++ b/tests/test_completion_path.c
@@ -0,0 +1,59 @@
+#include "test_core.h"
+
+#include "completion.h"
+#include "ecex.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test_completion_helpers(void) {
+ assert(ecex_ascii_strncasecmp("Alpha", "alpha", 5) == 0);
+ assert(ecex_ascii_strncasecmp("Alpha", "Alpine", 4) != 0);
+ assert(ecex_ascii_contains_ci("compile-buffer", "PILE") == 1);
+ assert(ecex_ascii_contains_ci("compile-buffer", "missing") == 0);
+
+ assert(ecex_fuzzy_score("find-file", "ff") > 0);
+ assert(ecex_fuzzy_score("find-file", "zz") < 0);
+ assert(ecex_fuzzy_score("find-file", "find") > ecex_fuzzy_score("other-find", "find"));
+
+ ecex_completion_item_t items[] = {
+ {"z-file", 10, 0, 0},
+ {"a-dir", 10, 1, 1},
+ {"b-file", 30, 0, 2},
+ };
+ qsort(items, 3, sizeof(items[0]), ecex_completion_item_compare);
+ assert(strcmp(items[0].value, "b-file") == 0);
+ assert(strcmp(items[1].value, "a-dir") == 0);
+ assert(strcmp(items[2].value, "z-file") == 0);
+}
+
+void test_path_helpers(void) {
+ char small[4];
+ assert(ecex_path_copy(small, sizeof(small), "abcd") != 0);
+ assert(strcmp(small, "abc") == 0);
+
+ char *joined = ecex_path_join("/tmp", "ecex-path-test.txt");
+ assert(joined);
+ assert(strcmp(joined, "/tmp/ecex-path-test.txt") == 0);
+ free(joined);
+
+ char *absolute = ecex_path_join("/tmp", "/var/log");
+ assert(absolute);
+ assert(strcmp(absolute, "/var/log") == 0);
+ free(absolute);
+
+ char *dir = ecex_path_dirname("/tmp/ecex/file.txt");
+ assert(dir);
+ assert(strcmp(dir, "/tmp/ecex") == 0);
+ free(dir);
+
+ char *base = ecex_path_basename_dup("/tmp/ecex/file.txt");
+ assert(base);
+ assert(strcmp(base, "file.txt") == 0);
+ free(base);
+
+ assert(ecex_path_is_image("photo.PNG") == 1);
+ assert(ecex_path_is_video("clip.MKV") == 1);
+ assert(ecex_path_is_media("notes.txt") == 0);
+}