1 #include "clar_libgit2.h"
5 check_dirname(const char *A
, const char *B
)
7 git_buf dir
= GIT_BUF_INIT
;
10 cl_assert(git_path_dirname_r(&dir
, A
) >= 0);
11 cl_assert_equal_s(B
, dir
.ptr
);
12 git_buf_dispose(&dir
);
14 cl_assert((dir2
= git_path_dirname(A
)) != NULL
);
15 cl_assert_equal_s(B
, dir2
);
20 check_basename(const char *A
, const char *B
)
22 git_buf base
= GIT_BUF_INIT
;
25 cl_assert(git_path_basename_r(&base
, A
) >= 0);
26 cl_assert_equal_s(B
, base
.ptr
);
27 git_buf_dispose(&base
);
29 cl_assert((base2
= git_path_basename(A
)) != NULL
);
30 cl_assert_equal_s(B
, base2
);
35 check_topdir(const char *A
, const char *B
)
39 cl_assert((dir
= git_path_topdir(A
)) != NULL
);
40 cl_assert_equal_s(B
, dir
);
44 check_joinpath(const char *path_a
, const char *path_b
, const char *expected_path
)
46 git_buf joined_path
= GIT_BUF_INIT
;
48 cl_git_pass(git_buf_joinpath(&joined_path
, path_a
, path_b
));
49 cl_assert_equal_s(expected_path
, joined_path
.ptr
);
51 git_buf_dispose(&joined_path
);
60 const char *expected_path
)
62 git_buf joined_path
= GIT_BUF_INIT
;
64 cl_git_pass(git_buf_join_n(&joined_path
, '/', 4,
65 path_a
, path_b
, path_c
, path_d
));
66 cl_assert_equal_s(expected_path
, joined_path
.ptr
);
68 git_buf_dispose(&joined_path
);
72 /* get the dirname of a path */
73 void test_core_path__00_dirname(void)
75 check_dirname(NULL
, ".");
76 check_dirname("", ".");
77 check_dirname("a", ".");
78 check_dirname("/", "/");
79 check_dirname("/usr", "/");
80 check_dirname("/usr/", "/");
81 check_dirname("/usr/lib", "/usr");
82 check_dirname("/usr/lib/", "/usr");
83 check_dirname("/usr/lib//", "/usr");
84 check_dirname("usr/lib", "usr");
85 check_dirname("usr/lib/", "usr");
86 check_dirname("usr/lib//", "usr");
87 check_dirname(".git/", ".");
89 check_dirname(REP16("/abc"), REP15("/abc"));
92 check_dirname("C:/", "C:/");
93 check_dirname("C:", "C:/");
94 check_dirname("C:/path/", "C:/");
95 check_dirname("C:/path", "C:/");
96 check_dirname("//computername/", "//computername/");
97 check_dirname("//computername", "//computername/");
98 check_dirname("//computername/path/", "//computername/");
99 check_dirname("//computername/path", "//computername/");
100 check_dirname("//computername/sub/path/", "//computername/sub");
101 check_dirname("//computername/sub/path", "//computername/sub");
105 /* get the base name of a path */
106 void test_core_path__01_basename(void)
108 check_basename(NULL
, ".");
109 check_basename("", ".");
110 check_basename("a", "a");
111 check_basename("/", "/");
112 check_basename("/usr", "usr");
113 check_basename("/usr/", "usr");
114 check_basename("/usr/lib", "lib");
115 check_basename("/usr/lib//", "lib");
116 check_basename("usr/lib", "lib");
118 check_basename(REP16("/abc"), "abc");
119 check_basename(REP1024("/abc"), "abc");
122 /* get the latest component in a path */
123 void test_core_path__02_topdir(void)
125 check_topdir(".git/", ".git/");
126 check_topdir("/.git/", ".git/");
127 check_topdir("usr/local/.git/", ".git/");
128 check_topdir("./.git/", ".git/");
129 check_topdir("/usr/.git/", ".git/");
130 check_topdir("/", "/");
131 check_topdir("a/", "a/");
133 cl_assert(git_path_topdir("/usr/.git") == NULL
);
134 cl_assert(git_path_topdir(".") == NULL
);
135 cl_assert(git_path_topdir("") == NULL
);
136 cl_assert(git_path_topdir("a") == NULL
);
139 /* properly join path components */
140 void test_core_path__05_joins(void)
142 check_joinpath("", "", "");
143 check_joinpath("", "a", "a");
144 check_joinpath("", "/a", "/a");
145 check_joinpath("a", "", "a/");
146 check_joinpath("a", "/", "a/");
147 check_joinpath("a", "b", "a/b");
148 check_joinpath("/", "a", "/a");
149 check_joinpath("/", "", "/");
150 check_joinpath("/a", "/b", "/a/b");
151 check_joinpath("/a", "/b/", "/a/b/");
152 check_joinpath("/a/", "b/", "/a/b/");
153 check_joinpath("/a/", "/b/", "/a/b/");
155 check_joinpath("/abcd", "/defg", "/abcd/defg");
156 check_joinpath("/abcd", "/defg/", "/abcd/defg/");
157 check_joinpath("/abcd/", "defg/", "/abcd/defg/");
158 check_joinpath("/abcd/", "/defg/", "/abcd/defg/");
160 check_joinpath("/abcdefgh", "/12345678", "/abcdefgh/12345678");
161 check_joinpath("/abcdefgh", "/12345678/", "/abcdefgh/12345678/");
162 check_joinpath("/abcdefgh/", "12345678/", "/abcdefgh/12345678/");
164 check_joinpath(REP1024("aaaa"), "", REP1024("aaaa") "/");
165 check_joinpath(REP1024("aaaa/"), "", REP1024("aaaa/"));
166 check_joinpath(REP1024("/aaaa"), "", REP1024("/aaaa") "/");
168 check_joinpath(REP1024("aaaa"), REP1024("bbbb"),
169 REP1024("aaaa") "/" REP1024("bbbb"));
170 check_joinpath(REP1024("/aaaa"), REP1024("/bbbb"),
171 REP1024("/aaaa") REP1024("/bbbb"));
174 /* properly join path components for more than one path */
175 void test_core_path__06_long_joins(void)
177 check_joinpath_n("", "", "", "", "");
178 check_joinpath_n("", "a", "", "", "a/");
179 check_joinpath_n("a", "", "", "", "a/");
180 check_joinpath_n("", "", "", "a", "a");
181 check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/");
182 check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d");
183 check_joinpath_n("abcd", "efgh", "ijkl", "mnop", "abcd/efgh/ijkl/mnop");
184 check_joinpath_n("abcd/", "efgh/", "ijkl/", "mnop/", "abcd/efgh/ijkl/mnop/");
185 check_joinpath_n("/abcd/", "/efgh/", "/ijkl/", "/mnop/", "/abcd/efgh/ijkl/mnop/");
187 check_joinpath_n(REP1024("a"), REP1024("b"), REP1024("c"), REP1024("d"),
188 REP1024("a") "/" REP1024("b") "/"
189 REP1024("c") "/" REP1024("d"));
190 check_joinpath_n(REP1024("/a"), REP1024("/b"), REP1024("/c"), REP1024("/d"),
191 REP1024("/a") REP1024("/b")
192 REP1024("/c") REP1024("/d"));
199 const char* expected
)
201 git_buf tgt
= GIT_BUF_INIT
;
203 git_buf_sets(&tgt
, path
);
204 cl_git_pass(git_path_to_dir(&tgt
));
205 cl_assert_equal_s(expected
, tgt
.ptr
);
207 git_buf_dispose(&tgt
);
214 const char* expected
)
216 size_t len
= strlen(path
);
217 char *buf
= git__malloc(len
+ 2);
220 strncpy(buf
, path
, len
+ 2);
222 git_path_string_to_dir(buf
, maxlen
);
224 cl_assert_equal_s(expected
, buf
);
229 /* convert paths to dirs */
230 void test_core_path__07_path_to_dir(void)
232 check_path_to_dir("", "");
233 check_path_to_dir(".", "./");
234 check_path_to_dir("./", "./");
235 check_path_to_dir("a/", "a/");
236 check_path_to_dir("ab", "ab/");
237 /* make sure we try just under and just over an expansion that will
240 check_path_to_dir("abcdef", "abcdef/");
241 check_path_to_dir("abcdefg", "abcdefg/");
242 check_path_to_dir("abcdefgh", "abcdefgh/");
243 check_path_to_dir("abcdefghi", "abcdefghi/");
244 check_path_to_dir(REP1024("abcd") "/", REP1024("abcd") "/");
245 check_path_to_dir(REP1024("abcd"), REP1024("abcd") "/");
247 check_string_to_dir("", 1, "");
248 check_string_to_dir(".", 1, ".");
249 check_string_to_dir(".", 2, "./");
250 check_string_to_dir(".", 3, "./");
251 check_string_to_dir("abcd", 3, "abcd");
252 check_string_to_dir("abcd", 4, "abcd");
253 check_string_to_dir("abcd", 5, "abcd/");
254 check_string_to_dir("abcd", 6, "abcd/");
257 /* join path to itself */
258 void test_core_path__08_self_join(void)
260 git_buf path
= GIT_BUF_INIT
;
264 cl_git_pass(git_buf_sets(&path
, "/foo"));
265 cl_assert_equal_s(path
.ptr
, "/foo");
266 cl_assert(asize
< path
.asize
);
269 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
, "this is a new string"));
270 cl_assert_equal_s(path
.ptr
, "/foo/this is a new string");
271 cl_assert(asize
< path
.asize
);
274 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
, "/grow the buffer, grow the buffer, grow the buffer"));
275 cl_assert_equal_s(path
.ptr
, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
276 cl_assert(asize
< path
.asize
);
278 git_buf_dispose(&path
);
279 cl_git_pass(git_buf_sets(&path
, "/foo/bar"));
281 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
+ 4, "baz"));
282 cl_assert_equal_s(path
.ptr
, "/bar/baz");
285 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
+ 4, "somethinglongenoughtorealloc"));
286 cl_assert_equal_s(path
.ptr
, "/baz/somethinglongenoughtorealloc");
287 cl_assert(asize
< path
.asize
);
289 git_buf_dispose(&path
);
292 static void check_percent_decoding(const char *expected_result
, const char *input
)
294 git_buf buf
= GIT_BUF_INIT
;
296 cl_git_pass(git__percent_decode(&buf
, input
));
297 cl_assert_equal_s(expected_result
, git_buf_cstr(&buf
));
299 git_buf_dispose(&buf
);
302 void test_core_path__09_percent_decode(void)
304 check_percent_decoding("abcd", "abcd");
305 check_percent_decoding("a2%", "a2%");
306 check_percent_decoding("a2%3", "a2%3");
307 check_percent_decoding("a2%%3", "a2%%3");
308 check_percent_decoding("a2%3z", "a2%3z");
309 check_percent_decoding("a,", "a%2c");
310 check_percent_decoding("a21", "a2%31");
311 check_percent_decoding("a2%1", "a2%%31");
312 check_percent_decoding("a bc ", "a%20bc%20");
313 check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED");
316 static void check_fromurl(const char *expected_result
, const char *input
, int should_fail
)
318 git_buf buf
= GIT_BUF_INIT
;
320 assert(should_fail
|| expected_result
);
323 cl_git_pass(git_path_fromurl(&buf
, input
));
324 cl_assert_equal_s(expected_result
, git_buf_cstr(&buf
));
326 cl_git_fail(git_path_fromurl(&buf
, input
));
328 git_buf_dispose(&buf
);
332 #define ABS_PATH_MARKER ""
334 #define ABS_PATH_MARKER "/"
337 void test_core_path__10_fromurl(void)
340 check_fromurl(NULL
, "a", 1);
341 check_fromurl(NULL
, "http:///c:/Temp%20folder/note.txt", 1);
342 check_fromurl(NULL
, "file://c:/Temp%20folder/note.txt", 1);
343 check_fromurl(NULL
, "file:////c:/Temp%20folder/note.txt", 1);
344 check_fromurl(NULL
, "file:///", 1);
345 check_fromurl(NULL
, "file:////", 1);
346 check_fromurl(NULL
, "file://servername/c:/Temp%20folder/note.txt", 1);
349 check_fromurl(ABS_PATH_MARKER
"c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0);
350 check_fromurl(ABS_PATH_MARKER
"c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0);
351 check_fromurl(ABS_PATH_MARKER
"c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0);
352 check_fromurl(ABS_PATH_MARKER
"a", "file:///a", 0);
361 #define CANCEL_VALUE 1234
363 static int check_one_walkup_step(void *ref
, const char *path
)
365 check_walkup_info
*info
= (check_walkup_info
*)ref
;
367 if (!info
->cancel_after
) {
368 cl_assert_equal_s(info
->expect
[info
->expect_idx
], "[CANCEL]");
371 info
->cancel_after
--;
373 cl_assert(info
->expect
[info
->expect_idx
] != NULL
);
374 cl_assert_equal_s(info
->expect
[info
->expect_idx
], path
);
380 void test_core_path__11_walkup(void)
382 git_buf p
= GIT_BUF_INIT
;
385 /* 1 */ "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
386 /* 2 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
387 /* 3 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
388 /* 4 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
389 /* 5 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL
,
390 /* 6 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL
,
391 /* 7 */ "this_is_a_path", "", NULL
,
392 /* 8 */ "this_is_a_path/", "", NULL
,
393 /* 9 */ "///a///b///c///d///e///", "///a///b///c///d///", "///a///b///c///", "///a///b///", "///a///", "///", NULL
,
394 /* 10 */ "a/b/c/", "a/b/", "a/", "", NULL
,
395 /* 11 */ "a/b/c", "a/b/", "a/", "", NULL
,
396 /* 12 */ "a/b/c/", "a/b/", "a/", NULL
,
420 check_walkup_info info
;
422 info
.expect
= expect
;
423 info
.cancel_after
= -1;
425 for (i
= 0, j
= 0; expect
[i
] != NULL
; i
++, j
++) {
427 git_buf_sets(&p
, expect
[i
]);
431 git_path_walk_up(&p
, root
[j
], check_one_walkup_step
, &info
)
434 cl_assert_equal_s(p
.ptr
, expect
[i
]);
435 cl_assert(expect
[info
.expect_idx
] == NULL
);
442 void test_core_path__11a_walkup_cancel(void)
444 git_buf p
= GIT_BUF_INIT
;
445 int cancel
[] = { 3, 2, 1, 0 };
447 "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL
,
448 "/a/b/c/d/e", "/a/b/c/d/", "[CANCEL]", NULL
,
449 "/a/b/c/d/e", "[CANCEL]", NULL
,
453 char *root
[] = { NULL
, NULL
, "/", "", NULL
};
455 check_walkup_info info
;
457 info
.expect
= expect
;
459 for (i
= 0, j
= 0; expect
[i
] != NULL
; i
++, j
++) {
461 git_buf_sets(&p
, expect
[i
]);
463 info
.cancel_after
= cancel
[j
];
468 git_path_walk_up(&p
, root
[j
], check_one_walkup_step
, &info
)
471 /* skip to next run of expectations */
472 while (expect
[i
] != NULL
) i
++;
478 void test_core_path__12_offset_to_path_root(void)
480 cl_assert(git_path_root("non/rooted/path") == -1);
481 cl_assert(git_path_root("/rooted/path") == 0);
484 /* Windows specific tests */
485 cl_assert(git_path_root("C:non/rooted/path") == -1);
486 cl_assert(git_path_root("C:/rooted/path") == 2);
487 cl_assert(git_path_root("//computername/sharefolder/resource") == 14);
488 cl_assert(git_path_root("//computername/sharefolder") == 14);
489 cl_assert(git_path_root("//computername") == -1);
493 #define NON_EXISTING_FILEPATH "i_hope_i_do_not_exist"
495 void test_core_path__13_cannot_prettify_a_non_existing_file(void)
497 git_buf p
= GIT_BUF_INIT
;
499 cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH
), false);
500 cl_assert_equal_i(GIT_ENOTFOUND
, git_path_prettify(&p
, NON_EXISTING_FILEPATH
, NULL
));
501 cl_assert_equal_i(GIT_ENOTFOUND
, git_path_prettify(&p
, NON_EXISTING_FILEPATH
"/so-do-i", NULL
));
506 void test_core_path__14_apply_relative(void)
508 git_buf p
= GIT_BUF_INIT
;
510 cl_git_pass(git_buf_sets(&p
, "/this/is/a/base"));
512 cl_git_pass(git_path_apply_relative(&p
, "../test"));
513 cl_assert_equal_s("/this/is/a/test", p
.ptr
);
515 cl_git_pass(git_path_apply_relative(&p
, "../../the/./end"));
516 cl_assert_equal_s("/this/is/the/end", p
.ptr
);
518 cl_git_pass(git_path_apply_relative(&p
, "./of/this/../the/string"));
519 cl_assert_equal_s("/this/is/the/end/of/the/string", p
.ptr
);
521 cl_git_pass(git_path_apply_relative(&p
, "../../../../../.."));
522 cl_assert_equal_s("/this/", p
.ptr
);
524 cl_git_pass(git_path_apply_relative(&p
, "../"));
525 cl_assert_equal_s("/", p
.ptr
);
527 cl_git_fail(git_path_apply_relative(&p
, "../../.."));
530 cl_git_pass(git_buf_sets(&p
, "d:/another/test"));
532 cl_git_pass(git_path_apply_relative(&p
, "../.."));
533 cl_assert_equal_s("d:/", p
.ptr
);
535 cl_git_pass(git_path_apply_relative(&p
, "from/here/to/../and/./back/."));
536 cl_assert_equal_s("d:/from/here/and/back/", p
.ptr
);
539 cl_git_pass(git_buf_sets(&p
, "https://my.url.com/test.git"));
541 cl_git_pass(git_path_apply_relative(&p
, "../another.git"));
542 cl_assert_equal_s("https://my.url.com/another.git", p
.ptr
);
544 cl_git_pass(git_path_apply_relative(&p
, "../full/path/url.patch"));
545 cl_assert_equal_s("https://my.url.com/full/path/url.patch", p
.ptr
);
547 cl_git_pass(git_path_apply_relative(&p
, ".."));
548 cl_assert_equal_s("https://my.url.com/full/path/", p
.ptr
);
550 cl_git_pass(git_path_apply_relative(&p
, "../../../"));
551 cl_assert_equal_s("https://", p
.ptr
);
554 cl_git_pass(git_buf_sets(&p
, "../../this/is/relative"));
556 cl_git_pass(git_path_apply_relative(&p
, "../../preserves/the/prefix"));
557 cl_assert_equal_s("../../this/preserves/the/prefix", p
.ptr
);
559 cl_git_pass(git_path_apply_relative(&p
, "../../../../that"));
560 cl_assert_equal_s("../../that", p
.ptr
);
562 cl_git_pass(git_path_apply_relative(&p
, "../there"));
563 cl_assert_equal_s("../../there", p
.ptr
);
567 static void assert_resolve_relative(
568 git_buf
*buf
, const char *expected
, const char *path
)
570 cl_git_pass(git_buf_sets(buf
, path
));
571 cl_git_pass(git_path_resolve_relative(buf
, 0));
572 cl_assert_equal_s(expected
, buf
->ptr
);
575 void test_core_path__15_resolve_relative(void)
577 git_buf buf
= GIT_BUF_INIT
;
579 assert_resolve_relative(&buf
, "", "");
580 assert_resolve_relative(&buf
, "", ".");
581 assert_resolve_relative(&buf
, "", "./");
582 assert_resolve_relative(&buf
, "..", "..");
583 assert_resolve_relative(&buf
, "../", "../");
584 assert_resolve_relative(&buf
, "..", "./..");
585 assert_resolve_relative(&buf
, "../", "./../");
586 assert_resolve_relative(&buf
, "../", "../.");
587 assert_resolve_relative(&buf
, "../", ".././");
588 assert_resolve_relative(&buf
, "../..", "../..");
589 assert_resolve_relative(&buf
, "../../", "../../");
591 assert_resolve_relative(&buf
, "/", "/");
592 assert_resolve_relative(&buf
, "/", "/.");
594 assert_resolve_relative(&buf
, "", "a/..");
595 assert_resolve_relative(&buf
, "", "a/../");
596 assert_resolve_relative(&buf
, "", "a/../.");
598 assert_resolve_relative(&buf
, "/a", "/a");
599 assert_resolve_relative(&buf
, "/a/", "/a/.");
600 assert_resolve_relative(&buf
, "/", "/a/../");
601 assert_resolve_relative(&buf
, "/", "/a/../.");
602 assert_resolve_relative(&buf
, "/", "/a/.././");
604 assert_resolve_relative(&buf
, "a", "a");
605 assert_resolve_relative(&buf
, "a/", "a/");
606 assert_resolve_relative(&buf
, "a/", "a/.");
607 assert_resolve_relative(&buf
, "a/", "a/./");
609 assert_resolve_relative(&buf
, "a/b", "a//b");
610 assert_resolve_relative(&buf
, "a/b/c", "a/b/c");
611 assert_resolve_relative(&buf
, "b/c", "./b/c");
612 assert_resolve_relative(&buf
, "a/c", "a/./c");
613 assert_resolve_relative(&buf
, "a/b/", "a/b/.");
615 assert_resolve_relative(&buf
, "/a/b/c", "///a/b/c");
616 assert_resolve_relative(&buf
, "/", "////");
617 assert_resolve_relative(&buf
, "/a", "///a");
618 assert_resolve_relative(&buf
, "/", "///.");
619 assert_resolve_relative(&buf
, "/", "///a/..");
621 assert_resolve_relative(&buf
, "../../path", "../../test//../././path");
622 assert_resolve_relative(&buf
, "../d", "a/b/../../../c/../d");
624 cl_git_pass(git_buf_sets(&buf
, "/.."));
625 cl_git_fail(git_path_resolve_relative(&buf
, 0));
627 cl_git_pass(git_buf_sets(&buf
, "/./.."));
628 cl_git_fail(git_path_resolve_relative(&buf
, 0));
630 cl_git_pass(git_buf_sets(&buf
, "/.//.."));
631 cl_git_fail(git_path_resolve_relative(&buf
, 0));
633 cl_git_pass(git_buf_sets(&buf
, "/../."));
634 cl_git_fail(git_path_resolve_relative(&buf
, 0));
636 cl_git_pass(git_buf_sets(&buf
, "/../.././../a"));
637 cl_git_fail(git_path_resolve_relative(&buf
, 0));
639 cl_git_pass(git_buf_sets(&buf
, "////.."));
640 cl_git_fail(git_path_resolve_relative(&buf
, 0));
642 /* things that start with Windows network paths */
644 assert_resolve_relative(&buf
, "//a/b/c", "//a/b/c");
645 assert_resolve_relative(&buf
, "//a/", "//a/b/..");
646 assert_resolve_relative(&buf
, "//a/b/c", "//a/Q/../b/x/y/../../c");
648 cl_git_pass(git_buf_sets(&buf
, "//a/b/../.."));
649 cl_git_fail(git_path_resolve_relative(&buf
, 0));
651 assert_resolve_relative(&buf
, "/a/b/c", "//a/b/c");
652 assert_resolve_relative(&buf
, "/a/", "//a/b/..");
653 assert_resolve_relative(&buf
, "/a/b/c", "//a/Q/../b/x/y/../../c");
654 assert_resolve_relative(&buf
, "/", "//a/b/../..");
657 git_buf_dispose(&buf
);
660 #define assert_common_dirlen(i, p, q) \
661 cl_assert_equal_i((i), git_path_common_dirlen((p), (q)));
663 void test_core_path__16_resolve_relative(void)
665 assert_common_dirlen(0, "", "");
666 assert_common_dirlen(0, "", "bar.txt");
667 assert_common_dirlen(0, "foo.txt", "bar.txt");
668 assert_common_dirlen(0, "foo.txt", "");
669 assert_common_dirlen(0, "foo/bar.txt", "bar/foo.txt");
670 assert_common_dirlen(0, "foo/bar.txt", "../foo.txt");
672 assert_common_dirlen(1, "/one.txt", "/two.txt");
673 assert_common_dirlen(4, "foo/one.txt", "foo/two.txt");
674 assert_common_dirlen(5, "/foo/one.txt", "/foo/two.txt");
676 assert_common_dirlen(6, "a/b/c/foo.txt", "a/b/c/d/e/bar.txt");
677 assert_common_dirlen(7, "/a/b/c/foo.txt", "/a/b/c/d/e/bar.txt");
680 void test_core_path__git_path_is_file(void)
682 cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS
));
683 cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE
, GIT_PATH_FS_HFS
));
684 cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES
, GIT_PATH_FS_HFS
));
685 cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES
, GIT_PATH_FS_HFS
));
686 cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS
));