Skip to content

Commit 8a670dc

Browse files
author
Edward Thomson
committed
patch::parse: test diff with simple rename
1 parent 38a347e commit 8a670dc

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

tests/diff/parse.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void test_diff_parse__invalid_patches_fails(void)
6565
}
6666

6767
static void test_tree_to_tree_computed_to_parsed(
68-
const char *sandbox, const char *a_id, const char *b_id)
68+
const char *sandbox, const char *a_id, const char *b_id,
69+
uint32_t diff_flags, uint32_t find_flags)
6970
{
7071
git_repository *repo;
7172
git_diff *computed, *parsed;
@@ -77,12 +78,17 @@ static void test_tree_to_tree_computed_to_parsed(
7778
repo = cl_git_sandbox_init(sandbox);
7879

7980
opts.id_abbrev = GIT_OID_HEXSZ;
80-
opts.flags = GIT_DIFF_SHOW_BINARY;
81+
opts.flags = GIT_DIFF_SHOW_BINARY | diff_flags;
82+
findopts.flags = find_flags;
8183

8284
cl_assert((a = resolve_commit_oid_to_tree(repo, a_id)) != NULL);
8385
cl_assert((b = resolve_commit_oid_to_tree(repo, b_id)) != NULL);
8486

8587
cl_git_pass(git_diff_tree_to_tree(&computed, repo, a, b, &opts));
88+
89+
if (find_flags)
90+
cl_git_pass(git_diff_find_similar(computed, &findopts));
91+
8692
cl_git_pass(git_diff_to_buf(&computed_buf,
8793
computed, GIT_DIFF_FORMAT_PATCH));
8894

@@ -104,25 +110,34 @@ static void test_tree_to_tree_computed_to_parsed(
104110

105111
void test_diff_parse__can_parse_generated_diff(void)
106112
{
107-
test_tree_to_tree_computed_to_parsed("diff", "d70d245e", "7a9e0b02");
108113
test_tree_to_tree_computed_to_parsed(
109-
"unsymlinked.git", "806999", "a8595c");
114+
"diff", "d70d245e", "7a9e0b02", 0, 0);
115+
test_tree_to_tree_computed_to_parsed(
116+
"unsymlinked.git", "806999", "a8595c", 0, 0);
110117
test_tree_to_tree_computed_to_parsed("diff",
111118
"d70d245ed97ed2aa596dd1af6536e4bfdb047b69",
112-
"7a9e0b02e63179929fed24f0a3e0f19168114d10");
119+
"7a9e0b02e63179929fed24f0a3e0f19168114d10", 0, 0);
120+
test_tree_to_tree_computed_to_parsed(
121+
"unsymlinked.git", "7fccd7", "806999", 0, 0);
113122
test_tree_to_tree_computed_to_parsed(
114-
"unsymlinked.git", "7fccd7", "806999");
123+
"unsymlinked.git", "7fccd7", "a8595c", 0, 0);
115124
test_tree_to_tree_computed_to_parsed(
116-
"unsymlinked.git", "7fccd7", "a8595c");
117-
test_tree_to_tree_computed_to_parsed("attr", "605812a", "370fe9ec22");
125+
"attr", "605812a", "370fe9ec22", 0, 0);
118126
test_tree_to_tree_computed_to_parsed(
119-
"attr", "f5b0af1fb4f5c", "370fe9ec22");
120-
test_tree_to_tree_computed_to_parsed("diff", "d70d245e", "d70d245e");
127+
"attr", "f5b0af1fb4f5c", "370fe9ec22", 0, 0);
128+
test_tree_to_tree_computed_to_parsed(
129+
"diff", "d70d245e", "d70d245e", 0, 0);
121130
test_tree_to_tree_computed_to_parsed("diff_format_email",
122131
"873806f6f27e631eb0b23e4b56bea2bfac14a373",
123-
"897d3af16ca9e420cd071b1c4541bd2b91d04c8c");
132+
"897d3af16ca9e420cd071b1c4541bd2b91d04c8c",
133+
GIT_DIFF_SHOW_BINARY, 0);
124134
test_tree_to_tree_computed_to_parsed("diff_format_email",
125135
"897d3af16ca9e420cd071b1c4541bd2b91d04c8c",
126-
"873806f6f27e631eb0b23e4b56bea2bfac14a373");
136+
"873806f6f27e631eb0b23e4b56bea2bfac14a373",
137+
GIT_DIFF_SHOW_BINARY, 0);
138+
test_tree_to_tree_computed_to_parsed("renames",
139+
"31e47d8c1fa36d7f8d537b96158e3f024de0a9f2",
140+
"2bc7f351d20b53f1c72c16c4b036e491c478c49a",
141+
0, GIT_DIFF_FIND_RENAMES);
127142
}
128143

0 commit comments

Comments
 (0)