OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package scanner | 5 package scanner |
6 | 6 |
7 import ( | 7 import ( |
8 "go/token" | 8 "go/token" |
9 "os" | 9 "os" |
10 "path/filepath" | 10 "path/filepath" |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 } | 643 } |
644 } | 644 } |
645 | 645 |
646 | 646 |
647 var errors = []struct { | 647 var errors = []struct { |
648 src string | 648 src string |
649 tok token.Token | 649 tok token.Token |
650 pos int | 650 pos int |
651 err string | 651 err string |
652 }{ | 652 }{ |
653 » {"\a", token.ILLEGAL, 0, "illegal character '\\a'"}, | 653 » {"\a", token.ILLEGAL, 0, "illegal character U+0007"}, |
654 » {`#`, token.ILLEGAL, 0, "illegal character '#'"}, | 654 » {`#`, token.ILLEGAL, 0, "illegal character U+0023 '#'"}, |
655 » {`…`, token.ILLEGAL, 0, "illegal character '…'"}, | 655 » {`…`, token.ILLEGAL, 0, "illegal character U+2026 '…'"}, |
656 {`' '`, token.CHAR, 0, ""}, | 656 {`' '`, token.CHAR, 0, ""}, |
657 {`''`, token.CHAR, 0, "illegal character literal"}, | 657 {`''`, token.CHAR, 0, "illegal character literal"}, |
658 {`'\8'`, token.CHAR, 2, "unknown escape sequence"}, | 658 {`'\8'`, token.CHAR, 2, "unknown escape sequence"}, |
659 {`'\08'`, token.CHAR, 3, "illegal character in escape sequence"}, | 659 {`'\08'`, token.CHAR, 3, "illegal character in escape sequence"}, |
660 {`'\x0g'`, token.CHAR, 4, "illegal character in escape sequence"}, | 660 {`'\x0g'`, token.CHAR, 4, "illegal character in escape sequence"}, |
661 {`'\Uffffffff'`, token.CHAR, 2, "escape sequence is invalid Unicode code
point"}, | 661 {`'\Uffffffff'`, token.CHAR, 2, "escape sequence is invalid Unicode code
point"}, |
662 {`'`, token.CHAR, 0, "character literal not terminated"}, | 662 {`'`, token.CHAR, 0, "character literal not terminated"}, |
663 {`""`, token.STRING, 0, ""}, | 663 {`""`, token.STRING, 0, ""}, |
664 {`"`, token.STRING, 0, "string not terminated"}, | 664 {`"`, token.STRING, 0, "string not terminated"}, |
665 {"``", token.STRING, 0, ""}, | 665 {"``", token.STRING, 0, ""}, |
(...skipping 11 matching lines...) Expand all Loading... |
677 {"\"abc\x00def\"", token.STRING, 4, "illegal character NUL"}, | 677 {"\"abc\x00def\"", token.STRING, 4, "illegal character NUL"}, |
678 {"\"abc\x80def\"", token.STRING, 4, "illegal UTF-8 encoding"}, | 678 {"\"abc\x80def\"", token.STRING, 4, "illegal UTF-8 encoding"}, |
679 } | 679 } |
680 | 680 |
681 | 681 |
682 func TestScanErrors(t *testing.T) { | 682 func TestScanErrors(t *testing.T) { |
683 for _, e := range errors { | 683 for _, e := range errors { |
684 checkError(t, e.src, e.tok, e.pos, e.err) | 684 checkError(t, e.src, e.tok, e.pos, e.err) |
685 } | 685 } |
686 } | 686 } |
OLD | NEW |