go/parser: expand test cases for bad import

R=gri
CC=golang-dev
https://golang.org/cl/5697047
This commit is contained in:
Russ Cox 2012-02-23 14:44:53 -05:00
parent 224f05ba88
commit 3a6a1f9e7e
1 changed files with 30 additions and 14 deletions

View File

@ -207,24 +207,40 @@ func TestVarScope(t *testing.T) {
} }
var imports = map[string]bool{ var imports = map[string]bool{
"a": true, `"a"`: true,
"a/b": true, "`a`": true,
"a.b": true, `"a/b"`: true,
"m\x61th": true, `"a.b"`: true,
"greek/αβ": true, `"m\x61th"`: true,
"": false, `"greek/αβ"`: true,
"\x00": false, `""`: false,
"\x7f": false,
"a!": false, // Each of these pairs tests both `` vs "" strings
"a b": false, // and also use of invalid characters spelled out as
`a\b`: false, // escape sequences and written directly.
"`a`": false, // For example `"\x00"` tests import "\x00"
"\x80\x80": false, // while "`\x00`" tests import `<actual-NUL-byte>`.
`"\x00"`: false,
"`\x00`": false,
`"\x7f"`: false,
"`\x7f`": false,
`"a!"`: false,
"`a!`": false,
`"a b"`: false,
"`a b`": false,
`"a\\b"`: false,
"`a\\b`": false,
"\"`a`\"": false,
"`\"a\"`": false,
`"\x80\x80"`: false,
"`\x80\x80`": false,
`"\xFFFD"`: false,
"`\xFFFD`": false,
} }
func TestImports(t *testing.T) { func TestImports(t *testing.T) {
for path, isValid := range imports { for path, isValid := range imports {
src := fmt.Sprintf("package p; import %q", path) src := fmt.Sprintf("package p; import %s", path)
_, err := ParseFile(fset, "", src, 0) _, err := ParseFile(fset, "", src, 0)
switch { switch {
case err != nil && isValid: case err != nil && isValid: