Skip to content

Commit 83532ca

Browse files
authored
Merge pull request sergi#70 from maksimov/master
Added more tests to improve coverage slightly
2 parents 0aae786 + fa26729 commit 83532ca

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

diffmatchpatch/diff_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,29 @@ func TestDiffDelta(t *testing.T) {
10741074
deltaDiffs, err = dmp.DiffFromDelta("", delta)
10751075
assert.Equal(t, diffs, deltaDiffs)
10761076
assert.Nil(t, err)
1077+
1078+
// Test blank tokens.
1079+
_, err = dmp.DiffFromDelta("", "")
1080+
assert.Nil(t, err)
1081+
1082+
// Test invalid diff operation "a"
1083+
_, err = dmp.DiffFromDelta("", "a")
1084+
if err == nil {
1085+
assert.Fail(t, "expected Invalid diff operation.")
1086+
}
1087+
1088+
// Test non-numeric parameter
1089+
_, err = dmp.DiffFromDelta("", "-")
1090+
if err == nil {
1091+
assert.Fail(t, "expected Invalid syntax.")
1092+
}
1093+
1094+
// Test negative parameter
1095+
_, err = dmp.DiffFromDelta("", "--1")
1096+
if err == nil {
1097+
assert.Fail(t, "expected Negative number.")
1098+
}
1099+
10771100
}
10781101

10791102
func TestDiffXIndex(t *testing.T) {

diffmatchpatch/patch_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestPatchFromText(t *testing.T) {
6565
{"@@ -1 +1 @@\n-a\n+b\n", ""},
6666
{"@@ -1,3 +0,0 @@\n-abc\n", ""},
6767
{"@@ -0,0 +1,3 @@\n+abc\n", ""},
68+
{"@@ _0,0 +0,0 @@\n+abc\n", "Invalid patch string: @@ _0,0 +0,0 @@"},
6869
{"Bad\nPatch\n", "Invalid patch string"},
6970
} {
7071
patches, err := dmp.PatchFromText(tc.Patch)
@@ -201,6 +202,10 @@ func TestPatchMakeAndPatchToText(t *testing.T) {
201202

202203
actual := dmp.PatchToText(patches)
203204
assert.Equal(t, "@@ -1,14 +1,16 @@\n Lorem \n+a \n ipsum do\n@@ -148,13 +148,12 @@\n m libero\n- \n vel.\n", actual)
205+
206+
// Check that empty Patch array is returned for no parameter call
207+
patches = dmp.PatchMake()
208+
assert.Equal(t, []Patch{}, patches)
204209
}
205210

206211
func TestPatchSplitMax(t *testing.T) {

0 commit comments

Comments
 (0)