apply: test postimages that grow/shrink original Test with some postimages that actually grow/shrink from the original, adding new lines or removing them. (Also do so without context to ensure that we can add/remove from a non-zero part of the line vector.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
diff --git a/tests/apply/fromfile.c b/tests/apply/fromfile.c
index 88a2f45..ec2b889 100644
--- a/tests/apply/fromfile.c
+++ b/tests/apply/fromfile.c
@@ -125,6 +125,48 @@ void test_apply_fromfile__lastline(void)
"file.txt", 0100644));
}
+void test_apply_fromfile__change_middle_shrink(void)
+{
+ cl_git_pass(validate_and_apply_patchfile(
+ FILE_ORIGINAL, strlen(FILE_ORIGINAL),
+ FILE_CHANGE_MIDDLE_SHRINK, strlen(FILE_CHANGE_MIDDLE_SHRINK),
+ PATCH_ORIGINAL_TO_CHANGE_MIDDLE_SHRINK, NULL,
+ "file.txt", 0100644));
+}
+
+void test_apply_fromfile__change_middle_shrink_nocontext(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_pass(validate_and_apply_patchfile(
+ FILE_ORIGINAL, strlen(FILE_ORIGINAL),
+ FILE_CHANGE_MIDDLE_SHRINK, strlen(FILE_CHANGE_MIDDLE_SHRINK),
+ PATCH_ORIGINAL_TO_MIDDLE_SHRINK_NOCONTEXT, &diff_opts,
+ "file.txt", 0100644));
+}
+
+void test_apply_fromfile__change_middle_grow(void)
+{
+ cl_git_pass(validate_and_apply_patchfile(
+ FILE_ORIGINAL, strlen(FILE_ORIGINAL),
+ FILE_CHANGE_MIDDLE_GROW, strlen(FILE_CHANGE_MIDDLE_GROW),
+ PATCH_ORIGINAL_TO_CHANGE_MIDDLE_GROW, NULL,
+ "file.txt", 0100644));
+}
+
+void test_apply_fromfile__change_middle_grow_nocontext(void)
+{
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
+ diff_opts.context_lines = 0;
+
+ cl_git_pass(validate_and_apply_patchfile(
+ FILE_ORIGINAL, strlen(FILE_ORIGINAL),
+ FILE_CHANGE_MIDDLE_GROW, strlen(FILE_CHANGE_MIDDLE_GROW),
+ PATCH_ORIGINAL_TO_MIDDLE_GROW_NOCONTEXT, &diff_opts,
+ "file.txt", 0100644));
+}
+
void test_apply_fromfile__prepend(void)
{
cl_git_pass(validate_and_apply_patchfile(
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index f4cb2ff..e097062 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -98,6 +98,95 @@
"-below it!\n" \
"+change to the last line.\n"
+/* A change of the middle where we remove many lines */
+
+#define FILE_CHANGE_MIDDLE_SHRINK \
+ "hey!\n" \
+ "i've changed a lot, but left the line\n" \
+ "below it!\n"
+
+#define PATCH_ORIGINAL_TO_CHANGE_MIDDLE_SHRINK \
+ "diff --git a/file.txt b/file.txt\n" \
+ "index 9432026..629cd35 100644\n" \
+ "--- a/file.txt\n" \
+ "+++ b/file.txt\n" \
+ "@@ -1,9 +1,3 @@\n" \
+ " hey!\n" \
+ "-this is some context!\n" \
+ "-around some lines\n" \
+ "-that will change\n" \
+ "-yes it is!\n" \
+ "-(this line is changed)\n" \
+ "-and this\n" \
+ "-is additional context\n" \
+ "+i've changed a lot, but left the line\n" \
+ " below it!\n"
+
+#define PATCH_ORIGINAL_TO_MIDDLE_SHRINK_NOCONTEXT \
+ "diff --git a/file.txt b/file.txt\n" \
+ "index 9432026..629cd35 100644\n" \
+ "--- a/file.txt\n" \
+ "+++ b/file.txt\n" \
+ "@@ -2,7 +2 @@ hey!\n" \
+ "-this is some context!\n" \
+ "-around some lines\n" \
+ "-that will change\n" \
+ "-yes it is!\n" \
+ "-(this line is changed)\n" \
+ "-and this\n" \
+ "-is additional context\n" \
+ "+i've changed a lot, but left the line\n"
+
+/* A change to the middle where we grow many lines */
+
+#define FILE_CHANGE_MIDDLE_GROW \
+ "hey!\n" \
+ "this is some context!\n" \
+ "around some lines\n" \
+ "that will change\n" \
+ "yes it is!\n" \
+ "this line is changed\n" \
+ "and this line is added\n" \
+ "so is this\n" \
+ "(this too)\n" \
+ "whee...\n" \
+ "and this\n" \
+ "is additional context\n" \
+ "below it!\n"
+
+#define PATCH_ORIGINAL_TO_CHANGE_MIDDLE_GROW \
+ "diff --git a/file.txt b/file.txt\n" \
+ "index 9432026..207ebca 100644\n" \
+ "--- a/file.txt\n" \
+ "+++ b/file.txt\n" \
+ "@@ -3,7 +3,11 @@ this is some context!\n" \
+ " around some lines\n" \
+ " that will change\n" \
+ " yes it is!\n" \
+ "-(this line is changed)\n" \
+ "+this line is changed\n" \
+ "+and this line is added\n" \
+ "+so is this\n" \
+ "+(this too)\n" \
+ "+whee...\n" \
+ " and this\n" \
+ " is additional context\n" \
+ " below it!\n"
+
+
+#define PATCH_ORIGINAL_TO_MIDDLE_GROW_NOCONTEXT \
+ "diff --git a/file.txt b/file.txt\n" \
+ "index 9432026..207ebca 100644\n" \
+ "--- a/file.txt\n" \
+ "+++ b/file.txt\n" \
+ "@@ -6 +6,5 @@ yes it is!\n" \
+ "-(this line is changed)\n" \
+ "+this line is changed\n" \
+ "+and this line is added\n" \
+ "+so is this\n" \
+ "+(this too)\n" \
+ "+whee...\n"
+
/* An insertion at the beginning of the file (and the resultant patch) */
#define FILE_PREPEND \