1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00
go/internal/lsp/diff/apply_edits_test.go
Ian Cottrell f7bb6f12f0 internal/lsp: do not allow diff.ApplyEdits to be replaced
We only need one implementation of this, it must cope with all inputs, and it
has no freedom in it's results, so it does not need to be pluggable.

Change-Id: I6fec0c339eb288649a670fc3e2cb00c726467e20
Reviewed-on: https://go-review.googlesource.com/c/tools/+/198377
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-04 02:16:33 +00:00

31 lines
770 B
Go

package diff_test
import (
"testing"
"golang.org/x/tools/internal/lsp/diff"
"golang.org/x/tools/internal/span"
)
func TestApplyEdits(t *testing.T) {
var testCases = []struct {
before string
edits []diff.TextEdit
want string
}{
{"", nil, ""},
{"X", []diff.TextEdit{{newSpan(0, 1), "Y"}}, "Y"},
{" X ", []diff.TextEdit{{newSpan(1, 2), "Y"}}, " Y "},
{" X X ", []diff.TextEdit{{newSpan(1, 2), "Y"}, {newSpan(3, 4), "Z"}}, " Y Z "},
}
for _, tc := range testCases {
if got := diff.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))
}