Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c4837a

Browse files
Edward Thomsonethomson
Edward Thomson
authored andcommitted
patch_parse: ensure we can parse a patch
1 parent 4e3637b commit 1c4837a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/patch/parse.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "clar_libgit2.h"
2+
3+
#include "patch_common.h"
4+
5+
void test_patch_parse__original_to_change_middle(void)
6+
{
7+
git_patch *patch;
8+
const git_diff_delta *delta;
9+
char idstr[GIT_OID_HEXSZ+1] = {0};
10+
11+
cl_git_pass(git_patch_from_patchfile(&patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE, strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE)));
12+
13+
cl_assert((delta = git_patch_get_delta(patch)) != NULL);
14+
cl_assert_equal_i(2, delta->nfiles);
15+
16+
cl_assert_equal_s(delta->old_file.path, "a/file.txt");
17+
cl_assert(delta->old_file.mode == 0100644);
18+
cl_assert_equal_i(7, delta->old_file.id_abbrev);
19+
git_oid_nfmt(idstr, delta->old_file.id_abbrev, &delta->old_file.id);
20+
cl_assert_equal_s(idstr, "9432026");
21+
cl_assert_equal_i(0, delta->old_file.size);
22+
23+
cl_assert_equal_s(delta->new_file.path, "b/file.txt");
24+
cl_assert(delta->new_file.mode == 0100644);
25+
cl_assert_equal_i(7, delta->new_file.id_abbrev);
26+
git_oid_nfmt(idstr, delta->new_file.id_abbrev, &delta->new_file.id);
27+
cl_assert_equal_s(idstr, "cd8fd12");
28+
cl_assert_equal_i(0, delta->new_file.size);
29+
30+
git_patch_free(patch);
31+
}

tests/patch/print.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "clar_libgit2.h"
2+
3+
#include "patch_common.h"
4+
5+
void test_patch_print__from_patchfile(void)
6+
{
7+
git_patch *patch;
8+
git_buf buf = GIT_BUF_INIT;
9+
10+
cl_git_pass(git_patch_from_patchfile(&patch, PATCH_ORIGINAL_TO_CHANGE_MIDDLE, strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE)));
11+
cl_git_pass(git_patch_to_buf(&buf, patch));
12+
13+
cl_assert_equal_s(PATCH_ORIGINAL_TO_CHANGE_MIDDLE, buf.ptr);
14+
15+
git_patch_free(patch);
16+
git_buf_free(&buf);
17+
}

0 commit comments

Comments
 (0)