1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

gofmt: fix //line handling

Fixes #2369.

R=gri
CC=golang-dev
https://golang.org/cl/5275048
This commit is contained in:
Russ Cox 2011-10-14 15:54:45 -04:00
parent 12ece77c14
commit 236aff31c5
4 changed files with 20 additions and 1 deletions

View File

@ -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) {

View 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
View File

@ -0,0 +1,9 @@
package main
func main() {}
// comment here
func f() {}
//line foo.go:1

View File

@ -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
}
}
}