]>
git.proxmox.com Git - libgit2.git/blob - tests/core/path.c
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
);
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
);
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_free(&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_free(&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:/path/", "C:/");
93 check_dirname("C:/path", "C:/");
94 check_dirname("//computername/path/", "//computername/");
95 check_dirname("//computername/path", "//computername/");
96 check_dirname("//computername/sub/path/", "//computername/sub");
97 check_dirname("//computername/sub/path", "//computername/sub");
101 /* get the base name of a path */
102 void test_core_path__01_basename(void)
104 check_basename(NULL
, ".");
105 check_basename("", ".");
106 check_basename("a", "a");
107 check_basename("/", "/");
108 check_basename("/usr", "usr");
109 check_basename("/usr/", "usr");
110 check_basename("/usr/lib", "lib");
111 check_basename("/usr/lib//", "lib");
112 check_basename("usr/lib", "lib");
114 check_basename(REP16("/abc"), "abc");
115 check_basename(REP1024("/abc"), "abc");
118 /* get the latest component in a path */
119 void test_core_path__02_topdir(void)
121 check_topdir(".git/", ".git/");
122 check_topdir("/.git/", ".git/");
123 check_topdir("usr/local/.git/", ".git/");
124 check_topdir("./.git/", ".git/");
125 check_topdir("/usr/.git/", ".git/");
126 check_topdir("/", "/");
127 check_topdir("a/", "a/");
129 cl_assert(git_path_topdir("/usr/.git") == NULL
);
130 cl_assert(git_path_topdir(".") == NULL
);
131 cl_assert(git_path_topdir("") == NULL
);
132 cl_assert(git_path_topdir("a") == NULL
);
135 /* properly join path components */
136 void test_core_path__05_joins(void)
138 check_joinpath("", "", "");
139 check_joinpath("", "a", "a");
140 check_joinpath("", "/a", "/a");
141 check_joinpath("a", "", "a/");
142 check_joinpath("a", "/", "a/");
143 check_joinpath("a", "b", "a/b");
144 check_joinpath("/", "a", "/a");
145 check_joinpath("/", "", "/");
146 check_joinpath("/a", "/b", "/a/b");
147 check_joinpath("/a", "/b/", "/a/b/");
148 check_joinpath("/a/", "b/", "/a/b/");
149 check_joinpath("/a/", "/b/", "/a/b/");
151 check_joinpath("/abcd", "/defg", "/abcd/defg");
152 check_joinpath("/abcd", "/defg/", "/abcd/defg/");
153 check_joinpath("/abcd/", "defg/", "/abcd/defg/");
154 check_joinpath("/abcd/", "/defg/", "/abcd/defg/");
156 check_joinpath("/abcdefgh", "/12345678", "/abcdefgh/12345678");
157 check_joinpath("/abcdefgh", "/12345678/", "/abcdefgh/12345678/");
158 check_joinpath("/abcdefgh/", "12345678/", "/abcdefgh/12345678/");
160 check_joinpath(REP1024("aaaa"), "", REP1024("aaaa") "/");
161 check_joinpath(REP1024("aaaa/"), "", REP1024("aaaa/"));
162 check_joinpath(REP1024("/aaaa"), "", REP1024("/aaaa") "/");
164 check_joinpath(REP1024("aaaa"), REP1024("bbbb"),
165 REP1024("aaaa") "/" REP1024("bbbb"));
166 check_joinpath(REP1024("/aaaa"), REP1024("/bbbb"),
167 REP1024("/aaaa") REP1024("/bbbb"));
170 /* properly join path components for more than one path */
171 void test_core_path__06_long_joins(void)
173 check_joinpath_n("", "", "", "", "");
174 check_joinpath_n("", "a", "", "", "a/");
175 check_joinpath_n("a", "", "", "", "a/");
176 check_joinpath_n("", "", "", "a", "a");
177 check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/");
178 check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d");
179 check_joinpath_n("abcd", "efgh", "ijkl", "mnop", "abcd/efgh/ijkl/mnop");
180 check_joinpath_n("abcd/", "efgh/", "ijkl/", "mnop/", "abcd/efgh/ijkl/mnop/");
181 check_joinpath_n("/abcd/", "/efgh/", "/ijkl/", "/mnop/", "/abcd/efgh/ijkl/mnop/");
183 check_joinpath_n(REP1024("a"), REP1024("b"), REP1024("c"), REP1024("d"),
184 REP1024("a") "/" REP1024("b") "/"
185 REP1024("c") "/" REP1024("d"));
186 check_joinpath_n(REP1024("/a"), REP1024("/b"), REP1024("/c"), REP1024("/d"),
187 REP1024("/a") REP1024("/b")
188 REP1024("/c") REP1024("/d"));
195 const char* expected
)
197 git_buf tgt
= GIT_BUF_INIT
;
199 git_buf_sets(&tgt
, path
);
200 cl_git_pass(git_path_to_dir(&tgt
));
201 cl_assert_equal_s(expected
, tgt
.ptr
);
210 const char* expected
)
212 size_t len
= strlen(path
);
213 char *buf
= git__malloc(len
+ 2);
216 strncpy(buf
, path
, len
+ 2);
218 git_path_string_to_dir(buf
, maxlen
);
220 cl_assert_equal_s(expected
, buf
);
225 /* convert paths to dirs */
226 void test_core_path__07_path_to_dir(void)
228 check_path_to_dir("", "");
229 check_path_to_dir(".", "./");
230 check_path_to_dir("./", "./");
231 check_path_to_dir("a/", "a/");
232 check_path_to_dir("ab", "ab/");
233 /* make sure we try just under and just over an expansion that will
236 check_path_to_dir("abcdef", "abcdef/");
237 check_path_to_dir("abcdefg", "abcdefg/");
238 check_path_to_dir("abcdefgh", "abcdefgh/");
239 check_path_to_dir("abcdefghi", "abcdefghi/");
240 check_path_to_dir(REP1024("abcd") "/", REP1024("abcd") "/");
241 check_path_to_dir(REP1024("abcd"), REP1024("abcd") "/");
243 check_string_to_dir("", 1, "");
244 check_string_to_dir(".", 1, ".");
245 check_string_to_dir(".", 2, "./");
246 check_string_to_dir(".", 3, "./");
247 check_string_to_dir("abcd", 3, "abcd");
248 check_string_to_dir("abcd", 4, "abcd");
249 check_string_to_dir("abcd", 5, "abcd/");
250 check_string_to_dir("abcd", 6, "abcd/");
253 /* join path to itself */
254 void test_core_path__08_self_join(void)
256 git_buf path
= GIT_BUF_INIT
;
260 cl_git_pass(git_buf_sets(&path
, "/foo"));
261 cl_assert_equal_s(path
.ptr
, "/foo");
262 cl_assert(asize
< path
.asize
);
265 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
, "this is a new string"));
266 cl_assert_equal_s(path
.ptr
, "/foo/this is a new string");
267 cl_assert(asize
< path
.asize
);
270 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
, "/grow the buffer, grow the buffer, grow the buffer"));
271 cl_assert_equal_s(path
.ptr
, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
272 cl_assert(asize
< path
.asize
);
275 cl_git_pass(git_buf_sets(&path
, "/foo/bar"));
277 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
+ 4, "baz"));
278 cl_assert_equal_s(path
.ptr
, "/bar/baz");
281 cl_git_pass(git_buf_joinpath(&path
, path
.ptr
+ 4, "somethinglongenoughtorealloc"));
282 cl_assert_equal_s(path
.ptr
, "/baz/somethinglongenoughtorealloc");
283 cl_assert(asize
< path
.asize
);
288 static void check_percent_decoding(const char *expected_result
, const char *input
)
290 git_buf buf
= GIT_BUF_INIT
;
292 cl_git_pass(git__percent_decode(&buf
, input
));
293 cl_assert_equal_s(expected_result
, git_buf_cstr(&buf
));
298 void test_core_path__09_percent_decode(void)
300 check_percent_decoding("abcd", "abcd");
301 check_percent_decoding("a2%", "a2%");
302 check_percent_decoding("a2%3", "a2%3");
303 check_percent_decoding("a2%%3", "a2%%3");
304 check_percent_decoding("a2%3z", "a2%3z");
305 check_percent_decoding("a,", "a%2c");
306 check_percent_decoding("a21", "a2%31");
307 check_percent_decoding("a2%1", "a2%%31");
308 check_percent_decoding("a bc ", "a%20bc%20");
309 check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED");
312 static void check_fromurl(const char *expected_result
, const char *input
, int should_fail
)
314 git_buf buf
= GIT_BUF_INIT
;
316 assert(should_fail
|| expected_result
);
319 cl_git_pass(git_path_fromurl(&buf
, input
));
320 cl_assert_equal_s(expected_result
, git_buf_cstr(&buf
));
322 cl_git_fail(git_path_fromurl(&buf
, input
));
328 #define ABS_PATH_MARKER ""
330 #define ABS_PATH_MARKER "/"
333 void test_core_path__10_fromurl(void)
336 check_fromurl(NULL
, "a", 1);
337 check_fromurl(NULL
, "http:///c:/Temp%20folder/note.txt", 1);
338 check_fromurl(NULL
, "file://c:/Temp%20folder/note.txt", 1);
339 check_fromurl(NULL
, "file:////c:/Temp%20folder/note.txt", 1);
340 check_fromurl(NULL
, "file:///", 1);
341 check_fromurl(NULL
, "file:////", 1);
342 check_fromurl(NULL
, "file://servername/c:/Temp%20folder/note.txt", 1);
345 check_fromurl(ABS_PATH_MARKER
"c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0);
346 check_fromurl(ABS_PATH_MARKER
"c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0);
347 check_fromurl(ABS_PATH_MARKER
"c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0);
348 check_fromurl(ABS_PATH_MARKER
"a", "file:///a", 0);
357 #define CANCEL_VALUE 1234
359 static int check_one_walkup_step(void *ref
, const char *path
)
361 check_walkup_info
*info
= (check_walkup_info
*)ref
;
363 if (!info
->cancel_after
) {
364 cl_assert_equal_s(info
->expect
[info
->expect_idx
], "[CANCEL]");
367 info
->cancel_after
--;
369 cl_assert(info
->expect
[info
->expect_idx
] != NULL
);
370 cl_assert_equal_s(info
->expect
[info
->expect_idx
], path
);
376 void test_core_path__11_walkup(void)
378 git_buf p
= GIT_BUF_INIT
;
381 /* 1 */ "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
382 /* 2 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
383 /* 3 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
384 /* 4 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL
,
385 /* 5 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL
,
386 /* 6 */ "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL
,
387 /* 7 */ "this_is_a_path", "", NULL
,
388 /* 8 */ "this_is_a_path/", "", NULL
,
389 /* 9 */ "///a///b///c///d///e///", "///a///b///c///d///", "///a///b///c///", "///a///b///", "///a///", "///", NULL
,
390 /* 10 */ "a/b/c/", "a/b/", "a/", "", NULL
,
391 /* 11 */ "a/b/c", "a/b/", "a/", "", NULL
,
392 /* 12 */ "a/b/c/", "a/b/", "a/", NULL
,
416 check_walkup_info info
;
418 info
.expect
= expect
;
419 info
.cancel_after
= -1;
421 for (i
= 0, j
= 0; expect
[i
] != NULL
; i
++, j
++) {
423 git_buf_sets(&p
, expect
[i
]);
427 git_path_walk_up(&p
, root
[j
], check_one_walkup_step
, &info
)
430 cl_assert_equal_s(p
.ptr
, expect
[i
]);
431 cl_assert(expect
[info
.expect_idx
] == NULL
);
438 void test_core_path__11a_walkup_cancel(void)
440 git_buf p
= GIT_BUF_INIT
;
441 int cancel
[] = { 3, 2, 1, 0 };
443 "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL
,
444 "/a/b/c/d/e", "/a/b/c/d/", "[CANCEL]", NULL
,
445 "/a/b/c/d/e", "[CANCEL]", NULL
,
449 char *root
[] = { NULL
, NULL
, "/", "", NULL
};
451 check_walkup_info info
;
453 info
.expect
= expect
;
455 for (i
= 0, j
= 0; expect
[i
] != NULL
; i
++, j
++) {
457 git_buf_sets(&p
, expect
[i
]);
459 info
.cancel_after
= cancel
[j
];
464 git_path_walk_up(&p
, root
[j
], check_one_walkup_step
, &info
)
467 /* skip to next run of expectations */
468 while (expect
[i
] != NULL
) i
++;
474 void test_core_path__12_offset_to_path_root(void)
476 cl_assert(git_path_root("non/rooted/path") == -1);
477 cl_assert(git_path_root("/rooted/path") == 0);
480 /* Windows specific tests */
481 cl_assert(git_path_root("C:non/rooted/path") == -1);
482 cl_assert(git_path_root("C:/rooted/path") == 2);
483 cl_assert(git_path_root("//computername/sharefolder/resource") == 14);
484 cl_assert(git_path_root("//computername/sharefolder") == 14);
485 cl_assert(git_path_root("//computername") == -1);
489 #define NON_EXISTING_FILEPATH "i_hope_i_do_not_exist"
491 void test_core_path__13_cannot_prettify_a_non_existing_file(void)
493 git_buf p
= GIT_BUF_INIT
;
495 cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH
), false);
496 cl_assert_equal_i(GIT_ENOTFOUND
, git_path_prettify(&p
, NON_EXISTING_FILEPATH
, NULL
));
497 cl_assert_equal_i(GIT_ENOTFOUND
, git_path_prettify(&p
, NON_EXISTING_FILEPATH
"/so-do-i", NULL
));
502 void test_core_path__14_apply_relative(void)
504 git_buf p
= GIT_BUF_INIT
;
506 cl_git_pass(git_buf_sets(&p
, "/this/is/a/base"));
508 cl_git_pass(git_path_apply_relative(&p
, "../test"));
509 cl_assert_equal_s("/this/is/a/test", p
.ptr
);
511 cl_git_pass(git_path_apply_relative(&p
, "../../the/./end"));
512 cl_assert_equal_s("/this/is/the/end", p
.ptr
);
514 cl_git_pass(git_path_apply_relative(&p
, "./of/this/../the/string"));
515 cl_assert_equal_s("/this/is/the/end/of/the/string", p
.ptr
);
517 cl_git_pass(git_path_apply_relative(&p
, "../../../../../.."));
518 cl_assert_equal_s("/this/", p
.ptr
);
520 cl_git_pass(git_path_apply_relative(&p
, "../"));
521 cl_assert_equal_s("/", p
.ptr
);
523 cl_git_fail(git_path_apply_relative(&p
, "../../.."));
526 cl_git_pass(git_buf_sets(&p
, "d:/another/test"));
528 cl_git_pass(git_path_apply_relative(&p
, "../.."));
529 cl_assert_equal_s("d:/", p
.ptr
);
531 cl_git_pass(git_path_apply_relative(&p
, "from/here/to/../and/./back/."));
532 cl_assert_equal_s("d:/from/here/and/back/", p
.ptr
);
535 cl_git_pass(git_buf_sets(&p
, "https://my.url.com/test.git"));
537 cl_git_pass(git_path_apply_relative(&p
, "../another.git"));
538 cl_assert_equal_s("https://my.url.com/another.git", p
.ptr
);
540 cl_git_pass(git_path_apply_relative(&p
, "../full/path/url.patch"));
541 cl_assert_equal_s("https://my.url.com/full/path/url.patch", p
.ptr
);
543 cl_git_pass(git_path_apply_relative(&p
, ".."));
544 cl_assert_equal_s("https://my.url.com/full/path/", p
.ptr
);
546 cl_git_pass(git_path_apply_relative(&p
, "../../../"));
547 cl_assert_equal_s("https://", p
.ptr
);
550 cl_git_pass(git_buf_sets(&p
, "../../this/is/relative"));
552 cl_git_pass(git_path_apply_relative(&p
, "../../preserves/the/prefix"));
553 cl_assert_equal_s("../../this/preserves/the/prefix", p
.ptr
);
555 cl_git_pass(git_path_apply_relative(&p
, "../../../../that"));
556 cl_assert_equal_s("../../that", p
.ptr
);
558 cl_git_pass(git_path_apply_relative(&p
, "../there"));
559 cl_assert_equal_s("../../there", p
.ptr
);
563 static void assert_resolve_relative(
564 git_buf
*buf
, const char *expected
, const char *path
)
566 cl_git_pass(git_buf_sets(buf
, path
));
567 cl_git_pass(git_path_resolve_relative(buf
, 0));
568 cl_assert_equal_s(expected
, buf
->ptr
);
571 void test_core_path__15_resolve_relative(void)
573 git_buf buf
= GIT_BUF_INIT
;
575 assert_resolve_relative(&buf
, "", "");
576 assert_resolve_relative(&buf
, "", ".");
577 assert_resolve_relative(&buf
, "", "./");
578 assert_resolve_relative(&buf
, "..", "..");
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
, "../../", "../../");
587 assert_resolve_relative(&buf
, "/", "/");
588 assert_resolve_relative(&buf
, "/", "/.");
590 assert_resolve_relative(&buf
, "", "a/..");
591 assert_resolve_relative(&buf
, "", "a/../");
592 assert_resolve_relative(&buf
, "", "a/../.");
594 assert_resolve_relative(&buf
, "/a", "/a");
595 assert_resolve_relative(&buf
, "/a/", "/a/.");
596 assert_resolve_relative(&buf
, "/", "/a/../");
597 assert_resolve_relative(&buf
, "/", "/a/../.");
598 assert_resolve_relative(&buf
, "/", "/a/.././");
600 assert_resolve_relative(&buf
, "a", "a");
601 assert_resolve_relative(&buf
, "a/", "a/");
602 assert_resolve_relative(&buf
, "a/", "a/.");
603 assert_resolve_relative(&buf
, "a/", "a/./");
605 assert_resolve_relative(&buf
, "a/b", "a//b");
606 assert_resolve_relative(&buf
, "a/b/c", "a/b/c");
607 assert_resolve_relative(&buf
, "b/c", "./b/c");
608 assert_resolve_relative(&buf
, "a/c", "a/./c");
609 assert_resolve_relative(&buf
, "a/b/", "a/b/.");
611 assert_resolve_relative(&buf
, "/a/b/c", "///a/b/c");
612 assert_resolve_relative(&buf
, "/", "////");
613 assert_resolve_relative(&buf
, "/a", "///a");
614 assert_resolve_relative(&buf
, "/", "///.");
615 assert_resolve_relative(&buf
, "/", "///a/..");
617 assert_resolve_relative(&buf
, "../../path", "../../test//../././path");
618 assert_resolve_relative(&buf
, "../d", "a/b/../../../c/../d");
620 cl_git_pass(git_buf_sets(&buf
, "/.."));
621 cl_git_fail(git_path_resolve_relative(&buf
, 0));
623 cl_git_pass(git_buf_sets(&buf
, "/./.."));
624 cl_git_fail(git_path_resolve_relative(&buf
, 0));
626 cl_git_pass(git_buf_sets(&buf
, "/.//.."));
627 cl_git_fail(git_path_resolve_relative(&buf
, 0));
629 cl_git_pass(git_buf_sets(&buf
, "/../."));
630 cl_git_fail(git_path_resolve_relative(&buf
, 0));
632 cl_git_pass(git_buf_sets(&buf
, "/../.././../a"));
633 cl_git_fail(git_path_resolve_relative(&buf
, 0));
635 cl_git_pass(git_buf_sets(&buf
, "////.."));
636 cl_git_fail(git_path_resolve_relative(&buf
, 0));
638 /* things that start with Windows network paths */
640 assert_resolve_relative(&buf
, "//a/b/c", "//a/b/c");
641 assert_resolve_relative(&buf
, "//a/", "//a/b/..");
642 assert_resolve_relative(&buf
, "//a/b/c", "//a/Q/../b/x/y/../../c");
644 cl_git_pass(git_buf_sets(&buf
, "//a/b/../.."));
645 cl_git_fail(git_path_resolve_relative(&buf
, 0));
647 assert_resolve_relative(&buf
, "/a/b/c", "//a/b/c");
648 assert_resolve_relative(&buf
, "/a/", "//a/b/..");
649 assert_resolve_relative(&buf
, "/a/b/c", "//a/Q/../b/x/y/../../c");
650 assert_resolve_relative(&buf
, "/", "//a/b/../..");
656 #define assert_common_dirlen(i, p, q) \
657 cl_assert_equal_i((i), git_path_common_dirlen((p), (q)));
659 void test_core_path__16_resolve_relative(void)
661 assert_common_dirlen(0, "", "");
662 assert_common_dirlen(0, "", "bar.txt");
663 assert_common_dirlen(0, "foo.txt", "bar.txt");
664 assert_common_dirlen(0, "foo.txt", "");
665 assert_common_dirlen(0, "foo/bar.txt", "bar/foo.txt");
666 assert_common_dirlen(0, "foo/bar.txt", "../foo.txt");
668 assert_common_dirlen(1, "/one.txt", "/two.txt");
669 assert_common_dirlen(4, "foo/one.txt", "foo/two.txt");
670 assert_common_dirlen(5, "/foo/one.txt", "/foo/two.txt");
672 assert_common_dirlen(6, "a/b/c/foo.txt", "a/b/c/d/e/bar.txt");
673 assert_common_dirlen(7, "/a/b/c/foo.txt", "/a/b/c/d/e/bar.txt");