Skip to content

Commit f7fa450

Browse files
committed
Make testing patches simple
1 parent 03923a5 commit f7fa450

File tree

4 files changed

+70
-71
lines changed

4 files changed

+70
-71
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -323,77 +323,8 @@ public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks()
323323
Assert.Equal(1, treeEntryChanges.LinesDeleted);
324324

325325
Assert.Equal(Mode.Nonexistent, changes["my-name-does-not-feel-right.txt"].Mode);
326-
327-
var expected = new StringBuilder()
328-
.Append("diff --git a/numbers.txt b/numbers.txt\n")
329-
.Append("index 7909961..4e935b7 100644\n")
330-
.Append("--- a/numbers.txt\n")
331-
.Append("+++ b/numbers.txt\n")
332-
.Append("@@ -1,4 +1,5 @@\n")
333-
.Append(" 1\n")
334-
.Append("+2\n")
335-
.Append(" 3\n")
336-
.Append(" 4\n")
337-
.Append(" 5\n")
338-
.Append("@@ -8,8 +9,9 @@\n")
339-
.Append(" 8\n")
340-
.Append(" 9\n")
341-
.Append(" 10\n")
342-
.Append("-12\n")
343-
.Append("+11\n")
344-
.Append(" 12\n")
345-
.Append(" 13\n")
346-
.Append(" 14\n")
347-
.Append(" 15\n")
348-
.Append("+16\n");
349-
350-
Assert.Equal(expected.ToString(), treeEntryChanges.Patch);
351-
352-
expected = new StringBuilder()
353-
.Append("diff --git a/my-name-does-not-feel-right.txt b/my-name-does-not-feel-right.txt\n")
354-
.Append("deleted file mode 100644\n")
355-
.Append("index e8953ab..0000000\n")
356-
.Append("--- a/my-name-does-not-feel-right.txt\n")
357-
.Append("+++ /dev/null\n")
358-
.Append("@@ -1,4 +0,0 @@\n")
359-
.Append("-That's a terrible name!\n")
360-
.Append("-I don't like it.\n")
361-
.Append("-People look down at me and laugh. :-(\n")
362-
.Append("-Really!!!!\n")
363-
.Append("diff --git a/numbers.txt b/numbers.txt\n")
364-
.Append("index 7909961..4e935b7 100644\n")
365-
.Append("--- a/numbers.txt\n")
366-
.Append("+++ b/numbers.txt\n")
367-
.Append("@@ -1,4 +1,5 @@\n")
368-
.Append(" 1\n")
369-
.Append("+2\n")
370-
.Append(" 3\n")
371-
.Append(" 4\n")
372-
.Append(" 5\n")
373-
.Append("@@ -8,8 +9,9 @@\n")
374-
.Append(" 8\n")
375-
.Append(" 9\n")
376-
.Append(" 10\n")
377-
.Append("-12\n")
378-
.Append("+11\n")
379-
.Append(" 12\n")
380-
.Append(" 13\n")
381-
.Append(" 14\n")
382-
.Append(" 15\n")
383-
.Append("+16\n")
384-
.Append("diff --git a/super-file.txt b/super-file.txt\n")
385-
.Append("new file mode 100644\n")
386-
.Append("index 0000000..16bdf1d\n")
387-
.Append("--- /dev/null\n")
388-
.Append("+++ b/super-file.txt\n")
389-
.Append("@@ -0,0 +1,5 @@\n")
390-
.Append("+That's a terrible name!\n")
391-
.Append("+I don't like it.\n")
392-
.Append("+People look down at me and laugh. :-(\n")
393-
.Append("+Really!!!!\n")
394-
.Append("+Yeah! Better!\n");
395-
396-
Assert.Equal(expected.ToString(), changes.Patch);
326+
Assert.Equal(GetExpectedPatch("f8d44d7...7252fe2-numbers.txt.patch"), treeEntryChanges.Patch);
327+
Assert.Equal(GetExpectedPatch("f8d44d7...7252fe2.patch"), changes.Patch);
397328
}
398329
}
399330

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/numbers.txt b/numbers.txt
2+
index 7909961..4e935b7 100644
3+
--- a/numbers.txt
4+
+++ b/numbers.txt
5+
@@ -1,4 +1,5 @@
6+
1
7+
+2
8+
3
9+
4
10+
5
11+
@@ -8,8 +9,9 @@
12+
8
13+
9
14+
10
15+
-12
16+
+11
17+
12
18+
13
19+
14
20+
15
21+
+16
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff --git a/my-name-does-not-feel-right.txt b/my-name-does-not-feel-right.txt
2+
deleted file mode 100644
3+
index e8953ab..0000000
4+
--- a/my-name-does-not-feel-right.txt
5+
+++ /dev/null
6+
@@ -1,4 +0,0 @@
7+
-That's a terrible name!
8+
-I don't like it.
9+
-People look down at me and laugh. :-(
10+
-Really!!!!
11+
diff --git a/numbers.txt b/numbers.txt
12+
index 7909961..4e935b7 100644
13+
--- a/numbers.txt
14+
+++ b/numbers.txt
15+
@@ -1,4 +1,5 @@
16+
1
17+
+2
18+
3
19+
4
20+
5
21+
@@ -8,8 +9,9 @@
22+
8
23+
9
24+
10
25+
-12
26+
+11
27+
12
28+
13
29+
14
30+
15
31+
+16
32+
diff --git a/super-file.txt b/super-file.txt
33+
new file mode 100644
34+
index 0000000..16bdf1d
35+
--- /dev/null
36+
+++ b/super-file.txt
37+
@@ -0,0 +1,5 @@
38+
+That's a terrible name!
39+
+I don't like it.
40+
+People look down at me and laugh. :-(
41+
+Really!!!!
42+
+Yeah! Better!

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,10 @@ protected string Touch(string parent, string file, string content = null)
221221

222222
return file;
223223
}
224+
225+
protected string GetExpectedPatch(string patchFilename)
226+
{
227+
return File.ReadAllText(Path.Combine(ResourcesDirectory.FullName, "expected_patches/" + patchFilename));
228+
}
224229
}
225230
}

0 commit comments

Comments
 (0)