mirror of https://github.com/kubernetes/kops.git
Fix a bug in diff formatting
This commit is contained in:
parent
8b60317b3f
commit
d4fd866ce3
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue