diff options
author | Vicent Marti <vicent@github.com> | 2014-01-22 09:35:25 -0800 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-01-22 09:35:25 -0800 |
commit | ec088fec9dc65621275b9f16d746820af67592de (patch) | |
tree | 548900c29909e116ec5c3c1fe41370bef3460ac5 /tests/diff/drivers.c | |
parent | af2b969b6f63dafa8c55b88cadbcc7631c2dd30b (diff) | |
parent | c05cd7924d2409741bb4cb1eb3ba843bea7ec4a2 (diff) | |
download | libgit2-ec088fec9dc65621275b9f16d746820af67592de.tar.gz |
Merge pull request #2069 from isilkor/patch_to_buf
Expose patch serialization to git_buf
Diffstat (limited to 'tests/diff/drivers.c')
-rw-r--r-- | tests/diff/drivers.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c index fbd1dff81..c80fad4c2 100644 --- a/tests/diff/drivers.c +++ b/tests/diff/drivers.c @@ -22,7 +22,7 @@ void test_diff_drivers__patterns(void) git_tree *one; git_diff *diff; git_patch *patch; - char *text; + git_buf buf = GIT_BUF_INIT; const char *expected0 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Comes through the blood of the vanguards who\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n"; const char *expected1 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\nBinary files a/untimely.txt and b/untimely.txt differ\n"; const char *expected2 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Heaven delivers on earth the Hour that cannot be\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n"; @@ -45,10 +45,10 @@ void test_diff_drivers__patterns(void) cl_assert_equal_i(1, (int)git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&text, patch)); - cl_assert_equal_s(expected0, text); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_s(expected0, buf.ptr); - git__free(text); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); @@ -60,10 +60,10 @@ void test_diff_drivers__patterns(void) cl_assert_equal_i(1, (int)git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&text, patch)); - cl_assert_equal_s(expected1, text); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_s(expected1, buf.ptr); - git__free(text); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); @@ -75,10 +75,10 @@ void test_diff_drivers__patterns(void) cl_assert_equal_i(1, (int)git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&text, patch)); - cl_assert_equal_s(expected0, text); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_s(expected0, buf.ptr); - git__free(text); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); @@ -92,10 +92,10 @@ void test_diff_drivers__patterns(void) cl_assert_equal_i(1, (int)git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&text, patch)); - cl_assert_equal_s(expected1, text); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_s(expected1, buf.ptr); - git__free(text); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); @@ -113,10 +113,10 @@ void test_diff_drivers__patterns(void) cl_assert_equal_i(1, (int)git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&text, patch)); - cl_assert_equal_s(expected2, text); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_s(expected2, buf.ptr); - git__free(text); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); @@ -129,7 +129,7 @@ void test_diff_drivers__long_lines(void) git_index *idx; git_diff *diff; git_patch *patch; - char *actual; + git_buf buf = GIT_BUF_INIT; const char *expected = "diff --git a/longlines.txt b/longlines.txt\nindex c1ce6ef..0134431 100644\n--- a/longlines.txt\n+++ b/longlines.txt\n@@ -3,3 +3,5 @@ Phasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissi\n Nam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\n Mauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\n Aliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n+newline\n+newline\n"; g_repo = cl_git_sandbox_init("empty_standard_repo"); @@ -145,18 +145,17 @@ void test_diff_drivers__long_lines(void) cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL)); cl_assert_equal_sz(1, git_diff_num_deltas(diff)); cl_git_pass(git_patch_from_diff(&patch, diff, 0)); - cl_git_pass(git_patch_to_str(&actual, patch)); + cl_git_pass(git_patch_to_buf(&buf, patch)); /* if chmod not supported, overwrite mode bits since anything is possible */ if (!cl_is_chmod_supported()) { - size_t actual_len = strlen(actual); - if (actual_len > 72 && memcmp(&actual[66], "100644", 6) != 0) - memcpy(&actual[66], "100644", 6); + if (buf.size > 72 && memcmp(&buf.ptr[66], "100644", 6) != 0) + memcpy(&buf.ptr[66], "100644", 6); } - cl_assert_equal_s(expected, actual); + cl_assert_equal_s(expected, buf.ptr); - free(actual); + git_buf_free(&buf); git_patch_free(patch); git_diff_free(diff); } |