diff options
author | Edward Thomson <ethomson@github.com> | 2016-04-25 00:35:48 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-05-26 13:01:09 -0500 |
commit | 7166bb16659790ae2b398e1e95c752f784f6f1d3 (patch) | |
tree | 1cc3a26e908ed54f579f5595332ba62bbba5a49c /tests/diff | |
parent | 94e488a056942f1bb1ebbe7c9f0c693937726609 (diff) | |
download | libgit2-7166bb16659790ae2b398e1e95c752f784f6f1d3.tar.gz |
introduce `git_diff_from_buffer` to parse diffs
Parse diff files into a `git_diff` structure.
Diffstat (limited to 'tests/diff')
-rw-r--r-- | tests/diff/parse.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/diff/parse.c b/tests/diff/parse.c new file mode 100644 index 000000000..8eb98423b --- /dev/null +++ b/tests/diff/parse.c @@ -0,0 +1,60 @@ +#include "clar_libgit2.h" +#include "patch.h" +#include "patch_parse.h" + +#include "../patch/patch_common.h" + +void test_diff_parse__nonpatches_fail_with_notfound(void) +{ + git_diff *diff; + const char *not = PATCH_NOT_A_PATCH; + const char *not_with_leading = "Leading text.\n" PATCH_NOT_A_PATCH; + const char *not_with_trailing = PATCH_NOT_A_PATCH "Trailing text.\n"; + const char *not_with_both = "Lead.\n" PATCH_NOT_A_PATCH "Trail.\n"; + + cl_git_fail_with(GIT_ENOTFOUND, + git_diff_from_buffer(&diff, + not, + strlen(not))); + cl_git_fail_with(GIT_ENOTFOUND, + git_diff_from_buffer(&diff, + not_with_leading, + strlen(not_with_leading))); + cl_git_fail_with(GIT_ENOTFOUND, + git_diff_from_buffer(&diff, + not_with_trailing, + strlen(not_with_trailing))); + cl_git_fail_with(GIT_ENOTFOUND, + git_diff_from_buffer(&diff, + not_with_both, + strlen(not_with_both))); +} + +static void test_parse_invalid_diff(const char *invalid_diff) +{ + git_diff *diff; + git_buf buf = GIT_BUF_INIT; + + /* throw some random (legitimate) diffs in with the given invalid + * one. + */ + git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE); + git_buf_puts(&buf, PATCH_BINARY_DELTA); + git_buf_puts(&buf, invalid_diff); + git_buf_puts(&buf, PATCH_ORIGINAL_TO_CHANGE_MIDDLE); + git_buf_puts(&buf, PATCH_BINARY_LITERAL); + + cl_git_fail_with(GIT_ERROR, + git_diff_from_buffer(&diff, buf.ptr, buf.size)); + + git_buf_free(&buf); +} + +void test_diff_parse__invalid_patches_fails(void) +{ + test_parse_invalid_diff(PATCH_CORRUPT_MISSING_NEW_FILE); + test_parse_invalid_diff(PATCH_CORRUPT_MISSING_OLD_FILE); + test_parse_invalid_diff(PATCH_CORRUPT_NO_CHANGES); + test_parse_invalid_diff(PATCH_CORRUPT_MISSING_HUNK_HEADER); +} + |