diff options
author | Robert Griesemer <gri@golang.org> | 2017-03-09 13:38:10 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2017-03-09 23:28:48 +0000 |
commit | 1f9f0ea32b2dcee027b107f2c3d0bc723274a810 (patch) | |
tree | 1c3d499526e0ab668b714ebc2cb0ac1ed76fb7dc /src/cmd/compile/internal/syntax/parser_test.go | |
parent | bfc164c64d33edfaf774b5c29b9bf5648a6447fb (diff) | |
download | go-1f9f0ea32b2dcee027b107f2c3d0bc723274a810.tar.gz go-1f9f0ea32b2dcee027b107f2c3d0bc723274a810.zip |
cmd/compile/internal/syntax: start line offset (column) numbers at 1
We could leave it alone and fix line offset (column) numbers when
reporting errors, but that is likely to cause confusion (internal
numbers don't match reported numbers). Instead, switch to default
numbering starting at 1.
For package syntax-internal use only, introduced constants defining
the line and column bases, and use them throughout the code and its
tests. It is possible to change these constants and package syntax
will continue to work. But changing them is going to break any client
that makes explicit assumptions about line and column numbers (which
is "all of them").
Change-Id: Ia3d136a8ec8d9372ed9c05ca47d3dff222cf030e
Reviewed-on: https://go-review.googlesource.com/37996
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser_test.go')
-rw-r--r-- | src/cmd/compile/internal/syntax/parser_test.go | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/syntax/parser_test.go b/src/cmd/compile/internal/syntax/parser_test.go index f7ada181dd..9028c41f37 100644 --- a/src/cmd/compile/internal/syntax/parser_test.go +++ b/src/cmd/compile/internal/syntax/parser_test.go @@ -188,20 +188,20 @@ func TestLineDirectives(t *testing.T) { for _, test := range []struct { src, msg string filename string - line, col uint + line, col uint // 0-based }{ // test validity of //line directive - {`//line :`, "invalid line number: ", "", 1, 8}, - {`//line :x`, "invalid line number: x", "", 1, 8}, - {`//line foo :`, "invalid line number: ", "", 1, 12}, - {`//line foo:123abc`, "invalid line number: 123abc", "", 1, 11}, - {`/**///line foo:x`, "syntax error: package statement must be first", "", 1, 16}, //line directive not at start of line - ignored - {`//line foo:0`, "invalid line number: 0", "", 1, 11}, - {fmt.Sprintf(`//line foo:%d`, lineMax+1), fmt.Sprintf("invalid line number: %d", lineMax+1), "", 1, 11}, + {`//line :`, "invalid line number: ", "", 0, 8}, + {`//line :x`, "invalid line number: x", "", 0, 8}, + {`//line foo :`, "invalid line number: ", "", 0, 12}, + {`//line foo:123abc`, "invalid line number: 123abc", "", 0, 11}, + {`/**///line foo:x`, "syntax error: package statement must be first", "", 0, 16}, //line directive not at start of line - ignored + {`//line foo:0`, "invalid line number: 0", "", 0, 11}, + {fmt.Sprintf(`//line foo:%d`, lineMax+1), fmt.Sprintf("invalid line number: %d", lineMax+1), "", 0, 11}, // test effect of //line directive on (relative) position information - {"//line foo:123\n foo", "syntax error: package statement must be first", "foo", 123, 3}, - {"//line foo:123\n//line bar:345\nfoo", "syntax error: package statement must be first", "bar", 345, 0}, + {"//line foo:123\n foo", "syntax error: package statement must be first", "foo", 123 - linebase, 3}, + {"//line foo:123\n//line bar:345\nfoo", "syntax error: package statement must be first", "bar", 345 - linebase, 0}, } { _, err := ParseBytes(nil, []byte(test.src), nil, nil, 0) if err == nil { @@ -219,11 +219,11 @@ func TestLineDirectives(t *testing.T) { if filename := perr.Pos.RelFilename(); filename != test.filename { t.Errorf("%s: got filename = %q; want %q", test.src, filename, test.filename) } - if line := perr.Pos.RelLine(); line != test.line { - t.Errorf("%s: got line = %d; want %d", test.src, line, test.line) + if line := perr.Pos.RelLine(); line != test.line+linebase { + t.Errorf("%s: got line = %d; want %d", test.src, line, test.line+linebase) } - if col := perr.Pos.Col(); col != test.col { - t.Errorf("%s: got col = %d; want %d", test.src, col, test.col) + if col := perr.Pos.Col(); col != test.col+colbase { + t.Errorf("%s: got col = %d; want %d", test.src, col, test.col+colbase) } } } |