aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/scanner_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2020-02-10 22:02:47 -0800
committerRobert Griesemer <gri@golang.org>2020-03-05 00:40:38 +0000
commitbfb903f2521ff24639aa7a5219330df38b06f412 (patch)
treec63369cd3ccf4bc9c91c21be02e1ba841e7bf4eb /src/cmd/compile/internal/syntax/scanner_test.go
parent17e6252c051e09a3a433620182fc54952a402d73 (diff)
downloadgo-bfb903f2521ff24639aa7a5219330df38b06f412.tar.gz
go-bfb903f2521ff24639aa7a5219330df38b06f412.zip
cmd/compile/internal/syntax: better scanner error messages
This is one of several changes that were part of a larger rewrite which I made in early 2019 after switching to the new number literal syntax implementation. The purpose of the rewrite was to simplify reading of source code (Unicode character by character) and speed up the scanner but was never submitted for review due to other priorities. Part 2 of 3: This change contains improvements to the scanner error messages: - Use "rune literal" rather than "character literal" to match the spec nomenclature. - Shorter, more to the point error messages. (For instance, "more than one character in rune literal" rather than "invalid character literal (more than one character)", etc.) Change-Id: I1aaf79003374a68dbb05926437ed305cf2a8ec96 Reviewed-on: https://go-review.googlesource.com/c/go/+/221602 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/scanner_test.go')
-rw-r--r--src/cmd/compile/internal/syntax/scanner_test.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go
index 612c59507e..f683341650 100644
--- a/src/cmd/compile/internal/syntax/scanner_test.go
+++ b/src/cmd/compile/internal/syntax/scanner_test.go
@@ -596,10 +596,10 @@ func TestScanErrors(t *testing.T) {
{"foo\n\n\xff ", "invalid UTF-8 encoding", 2, 0},
// token-level errors
- {"\u00BD" /* ½ */, "invalid identifier character U+00BD '½'", 0, 0},
- {"\U0001d736\U0001d737\U0001d738_½" /* 𝜶𝜷𝜸_½ */, "invalid identifier character U+00BD '½'", 0, 13 /* byte offset */},
+ {"\u00BD" /* ½ */, "invalid character U+00BD '½' in identifier", 0, 0},
+ {"\U0001d736\U0001d737\U0001d738_½" /* 𝜶𝜷𝜸_½ */, "invalid character U+00BD '½' in identifier", 0, 13 /* byte offset */},
{"\U0001d7d8" /* 𝟘 */, "identifier cannot begin with digit U+1D7D8 '𝟘'", 0, 0},
- {"foo\U0001d7d8_½" /* foo𝟘_½ */, "invalid identifier character U+00BD '½'", 0, 8 /* byte offset */},
+ {"foo\U0001d7d8_½" /* foo𝟘_½ */, "invalid character U+00BD '½' in identifier", 0, 8 /* byte offset */},
{"x + ~y", "invalid character U+007E '~'", 0, 4},
{"foo$bar = 0", "invalid character U+0024 '$'", 0, 3},
@@ -608,20 +608,20 @@ func TestScanErrors(t *testing.T) {
{"0123456789e0 /*\nfoobar", "comment not terminated", 0, 13}, // valid float constant
{"var a, b = 09, 07\n", "invalid digit '9' in octal literal", 0, 12},
- {`''`, "empty character literal or unescaped ' in character literal", 0, 1},
- {"'\n", "newline in character literal", 0, 1},
- {`'\`, "invalid character literal (missing closing ')", 0, 0},
- {`'\'`, "invalid character literal (missing closing ')", 0, 0},
- {`'\x`, "invalid character literal (missing closing ')", 0, 0},
- {`'\x'`, "non-hex character in escape sequence: '", 0, 3},
- {`'\y'`, "unknown escape sequence", 0, 2},
- {`'\x0'`, "non-hex character in escape sequence: '", 0, 4},
- {`'\00'`, "non-octal character in escape sequence: '", 0, 4},
+ {`''`, "empty rune literal or unescaped '", 0, 1},
+ {"'\n", "newline in rune literal", 0, 1},
+ {`'\`, "rune literal not terminated", 0, 0},
+ {`'\'`, "rune literal not terminated", 0, 0},
+ {`'\x`, "rune literal not terminated", 0, 0},
+ {`'\x'`, "invalid character '\\'' in hex escape", 0, 3},
+ {`'\y'`, "unknown escape", 0, 2},
+ {`'\x0'`, "invalid character '\\'' in hex escape", 0, 4},
+ {`'\00'`, "invalid character '\\'' in octal escape", 0, 4},
{`'\377' /*`, "comment not terminated", 0, 7}, // valid octal escape
- {`'\378`, "non-octal character in escape sequence: 8", 0, 4},
- {`'\400'`, "octal escape value > 255: 256", 0, 5},
- {`'xx`, "invalid character literal (missing closing ')", 0, 0},
- {`'xx'`, "invalid character literal (more than one character)", 0, 0},
+ {`'\378`, "invalid character '8' in octal escape", 0, 4},
+ {`'\400'`, "octal escape value 256 > 255", 0, 5},
+ {`'xx`, "rune literal not terminated", 0, 0},
+ {`'xx'`, "more than one character in rune literal", 0, 0},
{"\n \"foo\n", "newline in string", 1, 7},
{`"`, "string not terminated", 0, 0},
@@ -633,20 +633,20 @@ func TestScanErrors(t *testing.T) {
{`"\`, "string not terminated", 0, 0},
{`"\"`, "string not terminated", 0, 0},
{`"\x`, "string not terminated", 0, 0},
- {`"\x"`, "non-hex character in escape sequence: \"", 0, 3},
- {`"\y"`, "unknown escape sequence", 0, 2},
- {`"\x0"`, "non-hex character in escape sequence: \"", 0, 4},
- {`"\00"`, "non-octal character in escape sequence: \"", 0, 4},
+ {`"\x"`, "invalid character '\"' in hex escape", 0, 3},
+ {`"\y"`, "unknown escape", 0, 2},
+ {`"\x0"`, "invalid character '\"' in hex escape", 0, 4},
+ {`"\00"`, "invalid character '\"' in octal escape", 0, 4},
{`"\377" /*`, "comment not terminated", 0, 7}, // valid octal escape
- {`"\378"`, "non-octal character in escape sequence: 8", 0, 4},
- {`"\400"`, "octal escape value > 255: 256", 0, 5},
+ {`"\378"`, "invalid character '8' in octal escape", 0, 4},
+ {`"\400"`, "octal escape value 256 > 255", 0, 5},
- {`s := "foo\z"`, "unknown escape sequence", 0, 10},
- {`s := "foo\z00\nbar"`, "unknown escape sequence", 0, 10},
+ {`s := "foo\z"`, "unknown escape", 0, 10},
+ {`s := "foo\z00\nbar"`, "unknown escape", 0, 10},
{`"\x`, "string not terminated", 0, 0},
- {`"\x"`, "non-hex character in escape sequence: \"", 0, 3},
- {`var s string = "\x"`, "non-hex character in escape sequence: \"", 0, 18},
- {`return "\Uffffffff"`, "escape sequence is invalid Unicode code point U+FFFFFFFF", 0, 18},
+ {`"\x"`, "invalid character '\"' in hex escape", 0, 3},
+ {`var s string = "\x"`, "invalid character '\"' in hex escape", 0, 18},
+ {`return "\Uffffffff"`, "escape is invalid Unicode code point U+FFFFFFFF", 0, 18},
{"0b.0", "invalid radix point in binary literal", 0, 2},
{"0x.p0\n", "hexadecimal literal has no digits", 0, 3},