mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 17:12:51 +00:00
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.)
This commit is contained in:
parent
8cb27223b8
commit
0ff723cc90
@ -125,6 +125,48 @@ void test_apply_fromfile__lastline(void)
|
|||||||
"file.txt", 0100644));
|
"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)
|
void test_apply_fromfile__prepend(void)
|
||||||
{
|
{
|
||||||
cl_git_pass(validate_and_apply_patchfile(
|
cl_git_pass(validate_and_apply_patchfile(
|
||||||
|
@ -98,6 +98,95 @@
|
|||||||
"-below it!\n" \
|
"-below it!\n" \
|
||||||
"+change to the last line.\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) */
|
/* An insertion at the beginning of the file (and the resultant patch) */
|
||||||
|
|
||||||
#define FILE_PREPEND \
|
#define FILE_PREPEND \
|
||||||
|
Loading…
Reference in New Issue
Block a user