#define _POSIX_C_SOURCE 200809L #include "test_core.h" #include "completion.h" #include "ecex.h" #include #include #include #include #include #include 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); char root_dir[256]; snprintf(root_dir, sizeof(root_dir), "/tmp/ecex-project-test-%ld", (long)getpid()); char src_dir[320]; char nested_dir[384]; char marker[384]; char source_file[448]; snprintf(src_dir, sizeof(src_dir), "%s/src", root_dir); snprintf(nested_dir, sizeof(nested_dir), "%s/nested", src_dir); snprintf(marker, sizeof(marker), "%s/.ecex-project", root_dir); snprintf(source_file, sizeof(source_file), "%s/main.c", nested_dir); assert(mkdir(root_dir, 0700) == 0); assert(mkdir(src_dir, 0700) == 0); assert(mkdir(nested_dir, 0700) == 0); FILE *file = fopen(marker, "wb"); assert(file); fclose(file); char *project_root = ecex_project_root_for_file(source_file); char *normal_root = ecex_path_normalize(root_dir); assert(project_root && normal_root); assert(strcmp(project_root, normal_root) == 0); free(project_root); free(normal_root); unlink(marker); rmdir(nested_dir); rmdir(src_dir); rmdir(root_dir); }