1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
}
|