diff options
author | Robert Griesemer <gri@golang.org> | 2016-12-01 22:04:49 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2016-12-09 01:35:03 +0000 |
commit | 54ef0447fed1a59b95111b86a037c3443daf0b9b (patch) | |
tree | 204aa341250ac36b31f6cab4ee0c92887c834526 /src/cmd/compile/internal/syntax/scanner_test.go | |
parent | e97c8a592f20d390a97db1d516782c56badf258d (diff) | |
download | go-54ef0447fed1a59b95111b86a037c3443daf0b9b.tar.gz go-54ef0447fed1a59b95111b86a037c3443daf0b9b.zip |
[dev.inline] cmd/compile/internal/syntax: clean up error and pragma handling
Reviewed in and cherry-picked from https://go-review.googlesource.com/#/c/33873/.
- simplify error handling in source.go
(move handling of first error into parser, where it belongs)
- clean up error handling in scanner.go
- move pragma and position base handling from scanner
to parser where it belongs
- have separate error methods in parser to avoid confusion
with handlers from scanner.go and source.go
- (source.go) and (scanner.go, source.go, tokens.go)
may be stand-alone packages if so desired, which means
these files are now less entangled and easier to maintain
Change-Id: I81510fc7ef943b78eaa49092c0eab2075a05878c
Reviewed-on: https://go-review.googlesource.com/34235
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/syntax/scanner_test.go')
-rw-r--r-- | src/cmd/compile/internal/syntax/scanner_test.go | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go index b8ec811c18..988a74c287 100644 --- a/src/cmd/compile/internal/syntax/scanner_test.go +++ b/src/cmd/compile/internal/syntax/scanner_test.go @@ -22,7 +22,7 @@ func TestScanner(t *testing.T) { defer src.Close() var s scanner - s.init("parser.go", src, nil, nil) + s.init(src, nil, nil, false) for { s.next() if s.tok == _EOF { @@ -51,7 +51,7 @@ func TestTokens(t *testing.T) { // scan source var got scanner - got.init("", &bytesReader{buf}, nil, nil) + got.init(&bytesReader{buf}, nil, nil, false) got.next() for i, want := range sampleTokens { nlsemi := false @@ -317,38 +317,38 @@ func TestScanErrors(t *testing.T) { {`var s string = "\x"`, "non-hex character in escape sequence: \"", 1, 19}, {`return "\Uffffffff"`, "escape sequence is invalid Unicode code point", 1, 19}, - {`//line :`, "invalid line number: ", 1, 9}, - {`//line :x`, "invalid line number: x", 1, 9}, - {`//line foo :`, "invalid line number: ", 1, 13}, - {`//line foo:123abc`, "invalid line number: 123abc", 1, 12}, - {`/**///line foo:x`, "invalid line number: x", 1, 16}, - {`//line foo:0`, "invalid line number: 0", 1, 12}, - {fmt.Sprintf(`//line foo:%d`, lineMax+1), fmt.Sprintf("invalid line number: %d", lineMax+1), 1, 12}, + // TODO(gri) move these test cases into an appropriate parser test + // {`//line :`, "invalid line number: ", 1, 9}, + // {`//line :x`, "invalid line number: x", 1, 9}, + // {`//line foo :`, "invalid line number: ", 1, 13}, + // {`//line foo:123abc`, "invalid line number: 123abc", 1, 12}, + // {`/**///line foo:x`, "invalid line number: x", 1, 16}, + // {`//line foo:0`, "invalid line number: 0", 1, 12}, + // {fmt.Sprintf(`//line foo:%d`, lineMax+1), fmt.Sprintf("invalid line number: %d", lineMax+1), 1, 12}, // former problem cases {"package p\n\n\xef", "invalid UTF-8 encoding", 3, 1}, } { var s scanner nerrors := 0 - s.init("", &bytesReader{[]byte(test.src)}, func(err error) { + s.init(&bytesReader{[]byte(test.src)}, func(line, col uint, msg string) { nerrors++ // only check the first error - e := err.(Error) // we know it's an Error if nerrors == 1 { - if e.Msg != test.msg { - t.Errorf("%q: got msg = %q; want %q", test.src, e.Msg, test.msg) + if msg != test.msg { + t.Errorf("%q: got msg = %q; want %q", test.src, msg, test.msg) } - if e.Line != test.line { - t.Errorf("%q: got line = %d; want %d", test.src, e.Line, test.line) + if line != test.line { + t.Errorf("%q: got line = %d; want %d", test.src, line, test.line) } - if e.Col != test.col { - t.Errorf("%q: got col = %d; want %d", test.src, e.Col, test.col) + if col != test.col { + t.Errorf("%q: got col = %d; want %d", test.src, col, test.col) } } else if nerrors > 1 { // TODO(gri) make this use position info - t.Errorf("%q: got unexpected %q at line = %d", test.src, e.Msg, e.Line) + t.Errorf("%q: got unexpected %q at line = %d", test.src, msg, line) } - }, nil) + }, nil, true) for { s.next() |