Show the pending changes as a colored diff with line numbers
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDiffRows(t *testing.T) {
|
||||
if diffRows("a\nb", "a\nb") != nil {
|
||||
t.Fatal("equal texts have rows")
|
||||
}
|
||||
rows := diffRows("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11", "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\neleven\n12")
|
||||
var got []string
|
||||
for _, r := range rows {
|
||||
got = append(got, r.Class()+r.Mark())
|
||||
}
|
||||
want := []string{"gap", "ctx", "ctx", "del-", "add+", "add+"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("rows %v", got)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("rows %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
// The numbers are those of each side.
|
||||
del, add := rows[3], rows[4]
|
||||
if del.Old != 11 || del.New != 0 || del.Text != "11" || add.Old != 0 || add.New != 11 || add.Text != "eleven" {
|
||||
t.Fatalf("%+v %+v", del, add)
|
||||
}
|
||||
if rows[5].New != 12 {
|
||||
t.Fatalf("%+v", rows[5])
|
||||
}
|
||||
// The text form is what it always was.
|
||||
if d := diffLines("a\nb", "a\nc"); d != " a\n- b\n+ c\n" {
|
||||
t.Fatalf("%q", d)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user