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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include "clay_libgit2.h"
#include <fileops.h>
static void
check_dirname(const char *A, const char *B)
{
char dir[64], *dir2;
cl_assert(git_path_dirname_r(dir, sizeof(dir), A) >= 0);
cl_assert(strcmp(dir, B) == 0);
cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert(strcmp(dir2, B) == 0);
git__free(dir2);
}
static void
check_basename(const char *A, const char *B)
{
char base[64], *base2;
cl_assert(git_path_basename_r(base, sizeof(base), A) >= 0);
cl_assert(strcmp(base, B) == 0);
cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert(strcmp(base2, B) == 0);
git__free(base2);
}
static void
check_topdir(const char *A, const char *B)
{
const char *dir;
cl_assert((dir = git_path_topdir(A)) != NULL);
cl_assert(strcmp(dir, B) == 0);
}
static void
check_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{
char joined_path[GIT_PATH_MAX];
git_path_join(joined_path, path_a, path_b);
cl_assert(strcmp(joined_path, expected_path) == 0);
}
static void
check_joinpath_n(
const char *path_a,
const char *path_b,
const char *path_c,
const char *path_d,
const char *expected_path)
{
char joined_path[GIT_PATH_MAX];
git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d);
cl_assert(strcmp(joined_path, expected_path) == 0);
}
/* get the dirname of a path */
void test_core_path__0(void)
{
check_dirname(NULL, ".");
check_dirname("", ".");
check_dirname("a", ".");
check_dirname("/", "/");
check_dirname("/usr", "/");
check_dirname("/usr/", "/");
check_dirname("/usr/lib", "/usr");
check_dirname("/usr/lib/", "/usr");
check_dirname("/usr/lib//", "/usr");
check_dirname("usr/lib", "usr");
check_dirname("usr/lib/", "usr");
check_dirname("usr/lib//", "usr");
check_dirname(".git/", ".");
}
/* get the base name of a path */
void test_core_path__1(void)
{
check_basename(NULL, ".");
check_basename("", ".");
check_basename("a", "a");
check_basename("/", "/");
check_basename("/usr", "usr");
check_basename("/usr/", "usr");
check_basename("/usr/lib", "lib");
check_basename("/usr/lib//", "lib");
check_basename("usr/lib", "lib");
}
/* get the latest component in a path */
void test_core_path__2(void)
{
check_topdir(".git/", ".git/");
check_topdir("/.git/", ".git/");
check_topdir("usr/local/.git/", ".git/");
check_topdir("./.git/", ".git/");
check_topdir("/usr/.git/", ".git/");
check_topdir("/", "/");
check_topdir("a/", "a/");
cl_assert(git_path_topdir("/usr/.git") == NULL);
cl_assert(git_path_topdir(".") == NULL);
cl_assert(git_path_topdir("") == NULL);
cl_assert(git_path_topdir("a") == NULL);
}
/* properly join path components */
void test_core_path__5(void)
{
check_joinpath("", "", "");
check_joinpath("", "a", "a");
check_joinpath("", "/a", "/a");
check_joinpath("a", "", "a/");
check_joinpath("a", "/", "a/");
check_joinpath("a", "b", "a/b");
check_joinpath("/", "a", "/a");
check_joinpath("/", "", "/");
check_joinpath("/a", "/b", "/a/b");
check_joinpath("/a", "/b/", "/a/b/");
check_joinpath("/a/", "b/", "/a/b/");
check_joinpath("/a/", "/b/", "/a/b/");
}
/* properly join path components for more than one path */
void test_core_path__6(void)
{
check_joinpath_n("", "", "", "", "");
check_joinpath_n("", "a", "", "", "a/");
check_joinpath_n("a", "", "", "", "a/");
check_joinpath_n("", "", "", "a", "a");
check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/");
check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d");
}
|