summaryrefslogtreecommitdiff
path: root/src/pkg/go/scanner/scanner_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-02-26 11:23:12 -0800
committerRobert Griesemer <gri@golang.org>2010-02-26 11:23:12 -0800
commit5069bb6b179d7d7fdb6451ca9978636f5b886e51 (patch)
treeba451aa0f3405a89dab1c5bf62bf11a2af848964 /src/pkg/go/scanner/scanner_test.go
parentf30e23697d68504083c8be1937a5c728f5a07723 (diff)
downloadgolang-5069bb6b179d7d7fdb6451ca9978636f5b886e51.tar.gz
go/scanner: the position of '\n's chars must be the last position of the current line
Background: This didn't matter until recently, because '\n' don't appear as token starts in source code and thus the exact position was irrelevant (and set as was easiest in the code). With auto semicolon insertion, a virtual semicolon may be inserted when a '\n' is seen. The position of the semicolon is the position of the '\n'. Without this fix, these semicolons appeared on the next line instead of the line where they were inserted. This affected the association of comments to declarations in the parser. As a result, some lead comments where considered line comments, not collected in the ast, and not shown in godoc pages. (This affected only godoc pages, not gofmt-formatted programs). Fixes issue 592. R=rsc CC=golang-dev http://codereview.appspot.com/224068
Diffstat (limited to 'src/pkg/go/scanner/scanner_test.go')
-rw-r--r--src/pkg/go/scanner/scanner_test.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go
index ad54dfd1f..002a81dd9 100644
--- a/src/pkg/go/scanner/scanner_test.go
+++ b/src/pkg/go/scanner/scanner_test.go
@@ -219,11 +219,12 @@ func TestScan(t *testing.T) {
for _, e := range tokens {
src += e.lit + whitespace
}
+ src_linecount := newlineCount(src)
whitespace_linecount := newlineCount(whitespace)
// verify scan
index := 0
- epos := token.Position{"", 0, 1, 1}
+ epos := token.Position{"", 0, 1, 1} // expected position
nerrors := Tokenize("", []byte(src), &testErrorHandler{t}, ScanComments,
func(pos token.Position, tok token.Token, litb []byte) bool {
e := elt{token.EOF, "", special}
@@ -233,7 +234,8 @@ func TestScan(t *testing.T) {
lit := string(litb)
if tok == token.EOF {
lit = "<EOF>"
- epos.Column = 0
+ epos.Line = src_linecount
+ epos.Column = 1
}
checkPos(t, lit, pos, epos)
if tok != e.tok {