mirror of https://github.com/kubernetes/kops.git
Fix diff edge case for trailing diffs
This commit is contained in:
parent
58a8e9448a
commit
792bf5201e
|
@ -158,11 +158,13 @@ func buildDiffLines(lString, rString string) []lineRecord {
|
|||
}
|
||||
}
|
||||
|
||||
if l != "" && r != "" {
|
||||
if l == r {
|
||||
if l != "" && l == r {
|
||||
results = append(results, lineRecord{Type: diffmatchpatch.DiffEqual, Line: l})
|
||||
} else {
|
||||
if l != "" {
|
||||
results = append(results, lineRecord{Type: diffmatchpatch.DiffDelete, Line: l})
|
||||
}
|
||||
if r != "" {
|
||||
results = append(results, lineRecord{Type: diffmatchpatch.DiffInsert, Line: r})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,3 +135,39 @@ Line3`
|
|||
t.Fatalf("unexpected diff. expected=%v, actual=%v", expectedDiff, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Diff_4(t *testing.T) {
|
||||
l := `A
|
||||
B
|
||||
C
|
||||
D
|
||||
E
|
||||
F
|
||||
`
|
||||
r := `A
|
||||
B
|
||||
C
|
||||
D
|
||||
E
|
||||
F`
|
||||
expectedDiff := `...
|
||||
D
|
||||
E
|
||||
- F
|
||||
+ F
|
||||
`
|
||||
{
|
||||
dmp := diffmatchpatch.New()
|
||||
diffs := dmp.DiffMain(l, r, false)
|
||||
|
||||
// We do need to cleanup, as otherwise we get some spurious changes on complex diffs
|
||||
diffs = dmp.DiffCleanupSemantic(diffs)
|
||||
|
||||
t.Logf("diffs %v", diffs)
|
||||
}
|
||||
|
||||
actual := FormatDiff(l, r)
|
||||
if actual != expectedDiff {
|
||||
t.Fatalf("unexpected diff. expected=%s, actual=%s", expectedDiff, actual)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue