]>
Commit | Line | Data |
---|---|---|
eae0bfdc PP |
1 | #include "clar_libgit2.h" |
2 | #include "patch/patch_common.h" | |
3 | ||
4 | static void verify_patch_id(const char *diff_content, const char *expected_id) | |
5 | { | |
6 | git_oid expected_oid, actual_oid; | |
7 | git_diff *diff; | |
8 | ||
9 | cl_git_pass(git_oid_fromstr(&expected_oid, expected_id)); | |
10 | cl_git_pass(git_diff_from_buffer(&diff, diff_content, strlen(diff_content))); | |
11 | cl_git_pass(git_diff_patchid(&actual_oid, diff, NULL)); | |
12 | ||
13 | cl_assert_equal_oid(&expected_oid, &actual_oid); | |
14 | ||
15 | git_diff_free(diff); | |
16 | } | |
17 | ||
18 | void test_diff_patchid__simple_commit(void) | |
19 | { | |
20 | verify_patch_id(PATCH_SIMPLE_COMMIT, "06094b1948b878b7d9ff7560b4eae672a014b0ec"); | |
21 | } | |
22 | ||
22a2d3d5 UG |
23 | void test_diff_patchid__deleted_file(void) |
24 | { | |
25 | verify_patch_id(PATCH_DELETE_ORIGINAL, "d18507fe189f49c028b32c8c34e1ad98dd6a1aad"); | |
26 | verify_patch_id(PATCH_DELETED_FILE_2_HUNKS, "f31412498a17e6c3fbc635f2c5f9aa3ef4c1a9b7"); | |
27 | } | |
28 | ||
29 | void test_diff_patchid__created_file(void) | |
30 | { | |
31 | verify_patch_id(PATCH_ADD_ORIGINAL, "a7d39379308021465ae2ce65e338c048a3110db6"); | |
32 | } | |
33 | ||
34 | void test_diff_patchid__binary_file(void) | |
35 | { | |
36 | verify_patch_id(PATCH_ADD_BINARY_NOT_PRINTED, "2b31236b485faa30cf4dd33e4d6539829996739f"); | |
37 | } | |
38 | ||
39 | void test_diff_patchid__renamed_file(void) | |
40 | { | |
41 | verify_patch_id(PATCH_RENAME_EXACT, "4666d50cea4976f6f727448046d43461912058fd"); | |
42 | verify_patch_id(PATCH_RENAME_SIMILAR, "a795087575fcb940227be524488bedd6b3d3f438"); | |
43 | } | |
44 | ||
45 | void test_diff_patchid__modechange(void) | |
46 | { | |
47 | verify_patch_id(PATCH_MODECHANGE_UNCHANGED, "dbf3423ee98375ef1c72a79fbd29a049a2bae771"); | |
48 | verify_patch_id(PATCH_MODECHANGE_MODIFIED, "93aba696e1bbd2bbb73e3e3e62ed71f232137657"); | |
49 | } | |
50 | ||
51 | void test_diff_patchid__shuffle_hunks(void) | |
52 | { | |
53 | verify_patch_id(PATCH_DELETED_FILE_2_HUNKS_SHUFFLED, "f31412498a17e6c3fbc635f2c5f9aa3ef4c1a9b7"); | |
54 | } | |
55 | ||
eae0bfdc PP |
56 | void test_diff_patchid__filename_with_spaces(void) |
57 | { | |
58 | verify_patch_id(PATCH_APPEND_NO_NL, "f0ba05413beaef743b630e796153839462ee477a"); | |
59 | } | |
60 | ||
61 | void test_diff_patchid__multiple_hunks(void) | |
62 | { | |
63 | verify_patch_id(PATCH_MULTIPLE_HUNKS, "81e26c34643d17f521e57c483a6a637e18ba1f57"); | |
64 | } | |
65 | ||
66 | void test_diff_patchid__multiple_files(void) | |
67 | { | |
68 | verify_patch_id(PATCH_MULTIPLE_FILES, "192d1f49d23f2004517963aecd3f8a6c467f50ff"); | |
69 | } | |
70 | ||
71 | void test_diff_patchid__same_diff_with_differing_whitespace_has_same_id(void) | |
72 | { | |
73 | const char *tabs = | |
74 | "diff --git a/file.txt b/file.txt\n" | |
75 | "index 8fecc09..1d43a92 100644\n" | |
76 | "--- a/file.txt\n" | |
77 | "+++ b/file.txt\n" | |
78 | "@@ -1 +1 @@\n" | |
79 | "-old text\n" | |
80 | "+ new text\n"; | |
81 | const char *spaces = | |
82 | "diff --git a/file.txt b/file.txt\n" | |
83 | "index 8fecc09..1d43a92 100644\n" | |
84 | "--- a/file.txt\n" | |
85 | "+++ b/file.txt\n" | |
86 | "@@ -1 +1 @@\n" | |
87 | "-old text\n" | |
88 | "+ new text\n"; | |
89 | const char *id = "11efdd13c30f7a1056eac2ae2fb952da475e2c23"; | |
90 | ||
91 | verify_patch_id(tabs, id); | |
92 | verify_patch_id(spaces, id); | |
93 | } |