1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:24:39 -07:00
go/internal/lsp/source/format_test.go
Heschi Kreinick 95ece921ff internal/lsp/source: trim file very carefully
Apparently the AST will sometimes give us offsets past the end of the
file. Don't crash when it does.

Fixes golang/go#36610.

Change-Id: I3cfbf8645bfcea94a5d87bca5bef4236d657b2c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215119
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-01-17 20:34:13 +00:00

26 lines
326 B
Go

package source
import (
"go/parser"
"go/token"
"testing"
)
func TestTrimToImports(t *testing.T) {
const input = `package source
import (
m
"fmt"
)
func foo() {
fmt.Println("hi")
}
`
fs := token.NewFileSet()
f, _ := parser.ParseFile(fs, "foo.go", input, parser.ImportsOnly)
trimToImports(fs, f, []byte(input))
}