diff options
Diffstat (limited to 'tests/test_completion_path.c')
| -rw-r--r-- | tests/test_completion_path.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_completion_path.c b/tests/test_completion_path.c index 8170ee9..6615c38 100644 --- a/tests/test_completion_path.c +++ b/tests/test_completion_path.c @@ -1,11 +1,16 @@ +#define _POSIX_C_SOURCE 200809L + #include "test_core.h" #include "completion.h" #include "ecex.h" #include <assert.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> +#include <unistd.h> void test_completion_helpers(void) { assert(ecex_ascii_strncasecmp("Alpha", "alpha", 5) == 0); @@ -56,4 +61,34 @@ void test_path_helpers(void) { 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); } |
