-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_path.c
63 lines (52 loc) · 1.78 KB
/
test_path.c
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
60
61
62
63
#include "path.h"
#include "std.h"
void test_path_join(const char *dir, const char *name, const char *expected) {
char *path;
assert(dir != NULL);
assert(name != NULL);
assert(expected != NULL);
path = path_join(dir, name);
if (strcmp(path, expected) != 0) {
fprintf(stderr, "path is expected '%s', but got '%s'\n", expected,
path);
exit(1);
}
}
void test_path_dir(const char *path, const char *expected) {
char *dir;
assert(path != NULL);
assert(expected != NULL);
dir = path_dir(path);
if (strcmp(dir, expected) != 0) {
fprintf(stderr, "dir is expected '%s', but got %s\n", expected, dir);
exit(1);
}
}
void test_path(void) {
test_path_join("", "file", "file");
test_path_join(".", "file", "./file");
test_path_join("..", "file", "../file");
test_path_join("/", "file", "/file");
test_path_join("dir", "file", "dir/file");
test_path_join("dir/", "file", "dir/file");
test_path_join("dir/", "./file", "dir/./file");
test_path_join("dir", "./file", "dir/./file");
test_path_join("dir/", "./file", "dir/./file");
test_path_join("dir", "../file", "dir/../file");
test_path_join("dir/", "../file", "dir/../file");
test_path_dir("", "");
test_path_dir(".", "");
test_path_dir("a.c", "");
test_path_dir("/a.c", "/");
test_path_dir("./a.c", "./");
test_path_dir("../a.c", "../");
test_path_dir("dir/a.c", "dir/");
test_path_dir("dir/dir2/a.c", "dir/dir2/");
test_path_dir("./dir/dir2/a.c", "./dir/dir2/");
test_path_dir("./dir/dir2/./a.c", "./dir/dir2/./");
test_path_dir("/", "/");
test_path_dir("./", "./");
test_path_dir("../", "../");
test_path_dir("dir/", "dir/");
test_path_dir("dir/dir2/", "dir/dir2/");
}