1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:04:43 -07:00
go/internal/lsp/diff/apply_edits_test.go
Michael Matloob 27d1b4e4f3 internal/lsp/diff: rewrite ApplyEdits to work with sub-line diffs
This replaces the definition of ApplyEdits to be more like that in
go vet -fix, so that we can apply the results of suggested fixes.

Change-Id: Ib5724139464954e3790bc51ed1edc3ce4b2115ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193959
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-09 18:07:23 +00:00

30 lines
700 B
Go

package diff
import (
"testing"
"golang.org/x/tools/internal/span"
)
func TestApplyEdits(t *testing.T) {
var testCases = []struct {
before string
edits []TextEdit
want string
}{
{"", nil, ""},
{"X", []TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
{" X ", []TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
{" X X ", []TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
}
for _, tc := range testCases {
if got := applyEdits(tc.before, tc.edits); got != tc.want {
t.Errorf("applyEdits(%v, %v): got %v, want %v", tc.before, tc.edits, got, tc.want)
}
}
}
func newSpan(start, end int) span.Span {
return span.New("", span.NewPoint(0, 0, start), span.NewPoint(0, 0, end))
}