Skip to content

Commit 74798f5

Browse files
committed
Add a failing line diff test case
Current implementation produces wrong result because it calls `DiffMain` on the following 2 arguments: * `1,2,3,4,5,6,7,8,9,10` * `1,2,3,4,5,6,7,8,9,11` This numbers represent indices into the lines array. The algorithm finds that equal part of those strings is `1,2,3,4,5,6,7,8,9,1` and which is followed by `Delete 0` and `Insert `1`.
1 parent facec63 commit 74798f5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

diffmatchpatch/diff_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,38 @@ func TestMassiveRuneDiffConversion(t *testing.T) {
14681468
assert.NotEmpty(t, diffs)
14691469
}
14701470

1471+
func TestDiffPartialLineIndex(t *testing.T) {
1472+
dmp := New()
1473+
t1, t2, tt := dmp.DiffLinesToChars(
1474+
`line 1
1475+
line 2
1476+
line 3
1477+
line 4
1478+
line 5
1479+
line 6
1480+
line 7
1481+
line 8
1482+
line 9
1483+
line 10 text1`,
1484+
`line 1
1485+
line 2
1486+
line 3
1487+
line 4
1488+
line 5
1489+
line 6
1490+
line 7
1491+
line 8
1492+
line 9
1493+
line 10 text2`)
1494+
diffs := dmp.DiffMain(t1, t2, false)
1495+
diffs = dmp.DiffCharsToLines(diffs, tt)
1496+
assert.Equal(t, []Diff{
1497+
Diff{DiffEqual, "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\n"},
1498+
Diff{DiffDelete, "line 10 text1"},
1499+
Diff{DiffInsert, "line 10 text2"},
1500+
}, diffs)
1501+
}
1502+
14711503
func BenchmarkDiffMain(bench *testing.B) {
14721504
s1 := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
14731505
s2 := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"

0 commit comments

Comments
 (0)