summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-16 17:19:08 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-05 15:53:59 +0000
commit398d8bfe606feddf8db738250fc1960887f53685 (patch)
treee80201a589775b981aba3888a0fa277bb1ce2170
parentb8840db746452a6c8ea792b7362c554cc2a5870a (diff)
downloadlibgit2-398d8bfe606feddf8db738250fc1960887f53685.tar.gz
apply tests: tests a diff w/ many small changes
-rw-r--r--tests/apply/apply_helpers.h60
-rw-r--r--tests/apply/workdir.c52
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h
index a28a8131b..8f94d3998 100644
--- a/tests/apply/apply_helpers.h
+++ b/tests/apply/apply_helpers.h
@@ -52,6 +52,66 @@
"old mode 100644\n" \
"new mode 100755\n"
+#define DIFF_MANY_CHANGES_ONE \
+ "diff --git a/veal.txt b/veal.txt\n" \
+ "index 94d2c01..c9d7d5d 100644\n" \
+ "--- a/veal.txt\n" \
+ "+++ b/veal.txt\n" \
+ "@@ -1,2 +1,2 @@\n" \
+ "-VEAL SOUP!\n" \
+ "+VEAL SOUP\n" \
+ " \n" \
+ "@@ -4,3 +4,2 @@\n" \
+ " spoonful of black pepper pounded, and two of salt, with two or three\n" \
+ "-slices of lean ham; let it boil steadily two hours; skim it\n" \
+ " occasionally, then put into it a shin of veal, let it boil two hours\n" \
+ "@@ -8,3 +7,3 @@\n" \
+ " should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
+ "-of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ "+OF FLOUR very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ " mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
+ "@@ -12,2 +11,3 @@\n" \
+ " boiled two or three minutes to take off the raw taste of the eggs. If\n" \
+ "+Inserted line.\n" \
+ " the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
+ "@@ -15,3 +15,3 @@\n" \
+ " in, first taking off their skins, by letting them stand a few minutes in\n" \
+ "-hot water, when they may be easily peeled. When made in this way you\n" \
+ "+Changed line.\n" \
+ " must thicken it with the flour only. Any part of the veal may be used,\n"
+
+#define DIFF_MANY_CHANGES_TWO \
+ "diff --git a/veal.txt b/veal.txt\n" \
+ "index 94d2c01..6b943d6 100644\n" \
+ "--- a/veal.txt\n" \
+ "+++ b/veal.txt\n" \
+ "@@ -1,2 +1,2 @@\n" \
+ "-VEAL SOUP!\n" \
+ "+VEAL SOUP!!!\n" \
+ " \n" \
+ "@@ -4,3 +4,2 @@\n" \
+ " spoonful of black pepper pounded, and two of salt, with two or three\n" \
+ "-slices of lean ham; let it boil steadily two hours; skim it\n" \
+ " occasionally, then put into it a shin of veal, let it boil two hours\n" \
+ "@@ -8,3 +7,3 @@\n" \
+ " should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
+ "-of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
+ "+of flour very nicely, AND the yelks of two eggs beaten well, strain this\n" \
+ " mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
+ "@@ -12,2 +11,3 @@\n" \
+ " boiled two or three minutes to take off the raw taste of the eggs. If\n" \
+ "+New line.\n" \
+ " the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
+ "@@ -15,4 +15,5 @@\n" \
+ " in, first taking off their skins, by letting them stand a few minutes in\n" \
+ "-hot water, when they may be easily peeled. When made in this way you\n" \
+ "-must thicken it with the flour only. Any part of the veal may be used,\n" \
+ "-but the shin or knuckle is the nicest.\n" \
+ "+HOT water, when they may be easily peeled. When made in this way you\n" \
+ "+must THICKEN it with the flour only. Any part of the veal may be used,\n" \
+ "+but the shin OR knuckle is the nicest.\n" \
+ "+Another new line.\n" \
+
struct iterator_compare_data {
struct merge_index_entry *expected;
size_t cnt;
diff --git a/tests/apply/workdir.c b/tests/apply/workdir.c
index ab1dc2556..1a8292508 100644
--- a/tests/apply/workdir.c
+++ b/tests/apply/workdir.c
@@ -304,3 +304,55 @@ void test_apply_workdir__change_mode(void)
git_diff_free(diff);
#endif
}
+
+void test_apply_workdir__apply_many_changes_one(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ struct merge_index_entry workdir_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "c9d7d5d58088bc91f6e06f17ca3a205091568d3a", 0, "veal.txt" },
+ };
+ size_t workdir_expected_cnt = sizeof(workdir_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MANY_CHANGES_ONE, strlen(DIFF_MANY_CHANGES_ONE)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
+
+ validate_index_unchanged(repo);
+ validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
+
+ git_diff_free(diff);
+}
+
+void test_apply_workdir__apply_many_changes_two(void)
+{
+ git_diff *diff;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
+
+ struct merge_index_entry workdir_expected[] = {
+ { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
+ { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
+ { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
+ { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
+ { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
+ { 0100644, "6b943d65af6d8db74d747284fa4ca7d716ad5bbb", 0, "veal.txt" },
+ };
+ size_t workdir_expected_cnt = sizeof(workdir_expected) /
+ sizeof(struct merge_index_entry);
+
+ cl_git_pass(git_diff_from_buffer(&diff,
+ DIFF_MANY_CHANGES_TWO, strlen(DIFF_MANY_CHANGES_TWO)));
+ cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
+
+ validate_index_unchanged(repo);
+ validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
+
+ git_diff_free(diff);
+}