7 "golang.org/x/tools/internal/lsp/diff"
8 "golang.org/x/tools/internal/lsp/diff/difftest"
9 "golang.org/x/tools/internal/span"
12 func TestApplyEdits(t *testing.T) {
13 for _, tc := range difftest.TestCases {
14 t.Run(tc.Name, func(t *testing.T) {
16 if got := diff.ApplyEdits(tc.In, tc.Edits); got != tc.Out {
17 t.Errorf("ApplyEdits edits got %q, want %q", got, tc.Out)
19 if tc.LineEdits != nil {
20 if got := diff.ApplyEdits(tc.In, tc.LineEdits); got != tc.Out {
21 t.Errorf("ApplyEdits lineEdits got %q, want %q", got, tc.Out)
28 func TestLineEdits(t *testing.T) {
29 for _, tc := range difftest.TestCases {
30 t.Run(tc.Name, func(t *testing.T) {
32 // if line edits not specified, it is the same as edits
37 if got := diff.LineEdits(tc.In, tc.Edits); diffEdits(got, edits) {
38 t.Errorf("LineEdits got %q, want %q", got, edits)
44 func TestUnified(t *testing.T) {
45 for _, tc := range difftest.TestCases {
46 t.Run(tc.Name, func(t *testing.T) {
48 unified := fmt.Sprint(diff.ToUnified(difftest.FileA, difftest.FileB, tc.In, tc.Edits))
49 if unified != tc.Unified {
50 t.Errorf("edits got diff:\n%v\nexpected:\n%v", unified, tc.Unified)
52 if tc.LineEdits != nil {
53 unified := fmt.Sprint(diff.ToUnified(difftest.FileA, difftest.FileB, tc.In, tc.LineEdits))
54 if unified != tc.Unified {
55 t.Errorf("lineEdits got diff:\n%v\nexpected:\n%v", unified, tc.Unified)
62 func diffEdits(got, want []diff.TextEdit) bool {
63 if len(got) != len(want) {
66 for i, w := range want {
68 if span.Compare(w.Span, g.Span) != 0 {
71 if w.NewText != g.NewText {