Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/unit-tests/u-dir.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / unit-tests / u-dir.c` 75 lines ยท 2026 bytes Raw Blame History 1 #include "unit-test.h" 2 #include "dir.h" 3 4 #define TEST_WITHIN_DEPTH(path, depth, max_depth, expect) do { \ 5 int actual = within_depth(path, strlen(path), \ 6 depth, max_depth); \ 7 if (actual != expect) \ 8 cl_failf("path '%s' with depth '%d' and max-depth '%d': expected %d, got %d", \ 9 path, depth, max_depth, expect, actual); \ 10 } while (0) 11 12 void test_dir__within_depth(void) 13 { 14 /* depth = 0; max_depth = 0 */ 15 TEST_WITHIN_DEPTH("", 0, 0, 1); 16 TEST_WITHIN_DEPTH("file", 0, 0, 1); 17 TEST_WITHIN_DEPTH("a", 0, 0, 1); 18 TEST_WITHIN_DEPTH("a/file", 0, 0, 0); 19 TEST_WITHIN_DEPTH("a/b", 0, 0, 0); 20 TEST_WITHIN_DEPTH("a/b/file", 0, 0, 0); 21 22 /* depth = 0; max_depth = 1 */ 23 TEST_WITHIN_DEPTH("", 0, 1, 1); 24 TEST_WITHIN_DEPTH("file", 0, 1, 1); 25 TEST_WITHIN_DEPTH("a", 0, 1, 1); 26 TEST_WITHIN_DEPTH("a/file", 0, 1, 1); 27 TEST_WITHIN_DEPTH("a/b", 0, 1, 1); 28 TEST_WITHIN_DEPTH("a/b/file", 0, 1, 0); 29 30 /* depth = 1; max_depth = 1 */ 31 TEST_WITHIN_DEPTH("", 1, 1, 1); 32 TEST_WITHIN_DEPTH("file", 1, 1, 1); 33 TEST_WITHIN_DEPTH("a", 1, 1, 1); 34 TEST_WITHIN_DEPTH("a/file", 1, 1, 0); 35 TEST_WITHIN_DEPTH("a/b", 1, 1, 0); 36 TEST_WITHIN_DEPTH("a/b/file", 1, 1, 0); 37 38 /* depth = 1; max_depth = 0 */ 39 TEST_WITHIN_DEPTH("", 1, 0, 0); 40 TEST_WITHIN_DEPTH("file", 1, 0, 0); 41 TEST_WITHIN_DEPTH("a", 1, 0, 0); 42 TEST_WITHIN_DEPTH("a/file", 1, 0, 0); 43 TEST_WITHIN_DEPTH("a/b", 1, 0, 0); 44 TEST_WITHIN_DEPTH("a/b/file", 1, 0, 0); 45 46 47 } 48 49 void test_dir__common_prefix_skips_excluded_pathspec_items(void) 50 { 51 struct pathspec_item items[] = { 52 { 53 .match = "unrelated/path", 54 .magic = PATHSPEC_EXCLUDE, 55 .nowildcard_len = 14, 56 }, 57 { 58 .match = "foo/bar", 59 .nowildcard_len = 7, 60 }, 61 { 62 .match = "foo/baz", 63 .nowildcard_len = 7, 64 }, 65 }; 66 struct pathspec pathspec = { 67 .nr = ARRAY_SIZE(items), 68 .magic = PATHSPEC_EXCLUDE, 69 .items = items, 70 }; 71 char *prefix = common_prefix(&pathspec); 72 73 cl_assert_equal_s(prefix, "foo/"); 74 free(prefix); 75 }