mirror of
https://github.com/golang/go
synced 2024-11-25 09:07:58 -07:00
gofmt: fix //line handling
Fixes #2369. R=gri CC=golang-dev https://golang.org/cl/5275048
This commit is contained in:
parent
12ece77c14
commit
236aff31c5
@ -77,6 +77,7 @@ var tests = []struct {
|
||||
{"testdata/rewrite1.input", "-r=Foo->Bar"},
|
||||
{"testdata/rewrite2.input", "-r=int->bool"},
|
||||
{"testdata/stdin*.input", "-stdin"},
|
||||
{"testdata/comments.input", ""},
|
||||
}
|
||||
|
||||
func TestRewrite(t *testing.T) {
|
||||
|
9
src/cmd/gofmt/testdata/comments.golden
vendored
Normal file
9
src/cmd/gofmt/testdata/comments.golden
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
|
||||
// comment here
|
||||
|
||||
func f() {}
|
||||
|
||||
//line foo.go:1
|
9
src/cmd/gofmt/testdata/comments.input
vendored
Normal file
9
src/cmd/gofmt/testdata/comments.input
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
|
||||
// comment here
|
||||
|
||||
func f() {}
|
||||
|
||||
//line foo.go:1
|
@ -151,7 +151,7 @@ func (S *Scanner) interpretLineComment(text []byte) {
|
||||
filename = filepath.Join(S.dir, filename)
|
||||
}
|
||||
// update scanner position
|
||||
S.file.AddLineInfo(S.lineOffset, filename, line-1) // -1 since comment applies to next line
|
||||
S.file.AddLineInfo(S.lineOffset+len(text)+1, filename, line) // +len(text)+1 since comment applies to next line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user