mirror of
https://github.com/golang/go
synced 2024-11-18 19:14:40 -07:00
95ece921ff
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>
26 lines
326 B
Go
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))
|
|
}
|