2019-09-27 18:01:26 -06:00
|
|
|
package diff_test
|
2019-09-06 15:07:41 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-09-27 18:01:26 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/diff"
|
2019-09-06 15:07:41 -06:00
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestApplyEdits(t *testing.T) {
|
|
|
|
var testCases = []struct {
|
|
|
|
before string
|
2019-09-27 18:01:26 -06:00
|
|
|
edits []diff.TextEdit
|
2019-09-06 15:07:41 -06:00
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"", nil, ""},
|
2019-09-27 18:01:26 -06:00
|
|
|
{"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 "},
|
2019-09-06 15:07:41 -06:00
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
2019-09-27 18:01:26 -06:00
|
|
|
if got := diff.ApplyEdits(tc.before, tc.edits); got != tc.want {
|
2019-09-06 15:07:41 -06:00
|
|
|
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))
|
|
|
|
}
|