}
}
+func checkTokErr(t *testing.T, s *Scanner, line int, want rune, text string) {
+ prevCount := s.ErrorCount
+ checkTok(t, s, line, s.Scan(), want, text)
+ if s.ErrorCount != prevCount+1 {
+ t.Fatalf("want error for %q", text)
+ }
+}
+
func countNewlines(s string) int {
n := 0
for _, ch := range s {
testScan(t, GoTokens&^SkipComments)
}
+func TestIllegalExponent(t *testing.T) {
+ const src = "1.5e 1.5E 1e+ 1e- 1.5z"
+ s := new(Scanner).Init(strings.NewReader(src))
+ checkTokErr(t, s, 1, Float, "1.5e")
+ checkTokErr(t, s, 1, Float, "1.5E")
+ checkTokErr(t, s, 1, Float, "1e+")
+ checkTokErr(t, s, 1, Float, "1e-")
+ checkTok(t, s, 1, s.Scan(), Float, "1.5")
+ checkTok(t, s, 1, s.Scan(), Ident, "z")
+ checkTok(t, s, 1, s.Scan(), EOF, "")
+ if s.ErrorCount != 4 {
+ t.Errorf("%d errors, want 4", s.ErrorCount)
+ }
+}
+
func TestPosition(t *testing.T) {
src := makeSource("\t\t\t\t%s\n")
s := new(Scanner).Init(src)
testError(t, `0x`, "<input>:1:3", "illegal hexadecimal number", Int)
testError(t, `0xg`, "<input>:1:3", "illegal hexadecimal number", Int)
testError(t, `'aa'`, "<input>:1:4", "illegal char literal", Char)
+ testError(t, `1.5e`, "<input>:1:5", "illegal exponent", Float)
+ testError(t, `1.5E`, "<input>:1:5", "illegal exponent", Float)
+ testError(t, `1.5e+`, "<input>:1:6", "illegal exponent", Float)
+ testError(t, `1.5e-`, "<input>:1:6", "illegal exponent", Float)
testError(t, `'`, "<input>:1:2", "literal not terminated", Char)
testError(t, `'`+"\n", "<input>:1:2", "literal not terminated", Char)