Fix a bug in diff formatting

This commit is contained in:
Justin Santa Barbara 2016-12-14 11:41:17 -05:00
parent 8b60317b3f
commit d4fd866ce3
2 changed files with 23 additions and 1 deletions

View File

@ -121,7 +121,10 @@ func buildDiffLines(lString, rString string) []lineRecord {
}
case diffmatchpatch.DiffEqual:
if len(lines) > 0 {
if len(lines) == 1 {
l += lines[0]
r += lines[0]
} else if len(lines) > 1 {
if l != "" || r != "" {
l += lines[0]
r += lines[0]

View File

@ -117,3 +117,22 @@ F2`
t.Fatalf("unexpected diff. expected=%v, actual=%v", expectedDiff, actual)
}
}
func Test_Diff_ChangedLine(t *testing.T) {
l := `ABC123
Line2
Line3`
r := `ABCDEF
Line2
Line3`
expectedDiff := `+ ABCDEF
- ABC123
Line2
Line3
`
actual := FormatDiff(l, r)
if actual != expectedDiff {
t.Fatalf("unexpected diff. expected=%v, actual=%v", expectedDiff, actual)
}
}