1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:24:44 -07:00
go/internal/lsp/source/format_test.go
pjw 57a9e4404b internal/lsp: fix new bug duplicating comments after includes
Fixes https://github.com/golang/go/issues/39147

Change-Id: I6f78efccbabf21dbb00e56a49d88e26ff4733fba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234584
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-05-19 20:57:26 +00:00

31 lines
889 B
Go

package source
import (
"testing"
)
type data struct {
input, want string
}
func TestImportPrefix(t *testing.T) {
var tdata = []data{
{"package foo\n", "package foo\n"},
{"package foo\n\nfunc f(){}\n", "package foo\n"},
{"package foo\n\nimport \"fmt\"\n", "package foo\n\nimport \"fmt\""},
{"package foo\nimport (\n\"fmt\"\n)\n", "package foo\nimport (\n\"fmt\"\n)"},
{"\n\n\npackage foo\n", "\n\n\npackage foo\n"},
{"// hi \n\npackage foo //xx\nfunc _(){}\n", "// hi \n\npackage foo //xx\n"},
{"package foo //hi\n", "package foo //hi\n"},
{"//hi\npackage foo\n//a\n\n//b\n", "//hi\npackage foo\n//a\n\n//b\n"},
{"package a\n\nimport (\n \"fmt\"\n)\n//hi\n",
"package a\n\nimport (\n \"fmt\"\n)\n//hi\n"},
}
for i, x := range tdata {
got := importPrefix([]byte(x.input))
if got != x.want {
t.Errorf("%d: got\n%q, wanted\n%q", i, got, x.want)
}
}
}