]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: expand test cases for bad import
authorRuss Cox <rsc@golang.org>
Thu, 23 Feb 2012 19:44:53 +0000 (14:44 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 23 Feb 2012 19:44:53 +0000 (14:44 -0500)
R=gri
CC=golang-dev
https://golang.org/cl/5697047

src/pkg/go/parser/parser_test.go

index da0df14741b0f2b711e7b8a8b58f514879348193..93ca3d6aa39e96645c61821fd5a43853ce4404bd 100644 (file)
@@ -207,24 +207,40 @@ func TestVarScope(t *testing.T) {
 }
 
 var imports = map[string]bool{
-       "a":        true,
-       "a/b":      true,
-       "a.b":      true,
-       "m\x61th":  true,
-       "greek/αβ": true,
-       "":         false,
-       "\x00":     false,
-       "\x7f":     false,
-       "a!":       false,
-       "a b":      false,
-       `a\b`:      false,
-       "`a`":      false,
-       "\x80\x80": false,
+       `"a"`:        true,
+       "`a`":        true,
+       `"a/b"`:      true,
+       `"a.b"`:      true,
+       `"m\x61th"`:  true,
+       `"greek/αβ"`: true,
+       `""`:         false,
+
+       // Each of these pairs tests both `` vs "" strings
+       // and also use of invalid characters spelled out as
+       // escape sequences and written directly.
+       // For example `"\x00"` tests import "\x00"
+       // 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) {
        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)
                switch {
                case err != nil && isValid: