diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2019-07-20 11:24:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-20 11:24:37 +0100 |
| commit | fd7a384b6849a407677c592f269603f4075d662a (patch) | |
| tree | 9943a282f1d882946d824c263f58346c3a9b5b71 /tests/patch/parse.c | |
| parent | f33ca472d1a160ab5abbdf07d434455d7d1ee15c (diff) | |
| parent | b08932824e1ca202f1fcb81e94d329b77715a17c (diff) | |
| download | libgit2-fd7a384b6849a407677c592f269603f4075d662a.tar.gz | |
Merge pull request #5159 from pks-t/pks/patch-parse-old-missing-nl
patch_parse: handle missing newline indicator in old file
Diffstat (limited to 'tests/patch/parse.c')
| -rw-r--r-- | tests/patch/parse.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/tests/patch/parse.c b/tests/patch/parse.c index 7eb987920..b89322ff3 100644 --- a/tests/patch/parse.c +++ b/tests/patch/parse.c @@ -27,6 +27,18 @@ static void ensure_patch_validity(git_patch *patch) cl_assert_equal_i(0, delta->new_file.size); } +static void ensure_identical_patch_inout(const char *content) { + git_buf buf = GIT_BUF_INIT; + git_patch *patch; + + cl_git_pass(git_patch_from_buffer(&patch, content, strlen(content), NULL)); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_strn(git_buf_cstr(&buf), content, strlen(content)); + + git_patch_free(patch); + git_buf_dispose(&buf); +} + void test_patch_parse__original_to_change_middle(void) { git_patch *patch; @@ -102,11 +114,19 @@ void test_patch_parse__invalid_patches_fails(void) strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL)); } +void test_patch_parse__no_newline_at_end_of_new_file(void) +{ + ensure_identical_patch_inout(PATCH_APPEND_NO_NL); +} + +void test_patch_parse__no_newline_at_end_of_old_file(void) +{ + ensure_identical_patch_inout(PATCH_APPEND_NO_NL_IN_OLD_FILE); +} + void test_patch_parse__files_with_whitespaces_succeeds(void) { - git_patch *patch; - cl_git_pass(git_patch_from_buffer(&patch, PATCH_NAME_WHITESPACE, strlen(PATCH_NAME_WHITESPACE), NULL)); - git_patch_free(patch); + ensure_identical_patch_inout(PATCH_NAME_WHITESPACE); } void test_patch_parse__lifetime_of_patch_does_not_depend_on_buffer(void) |
