Skip to content

Commit 3a6a1f9

Browse files
committed
go/parser: expand test cases for bad import
R=gri CC=golang-dev https://golang.org/cl/5697047
1 parent 224f05b commit 3a6a1f9

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/pkg/go/parser/parser_test.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,24 +207,40 @@ func TestVarScope(t *testing.T) {
207207
}
208208

209209
var imports = map[string]bool{
210-
"a": true,
211-
"a/b": true,
212-
"a.b": true,
213-
"m\x61th": true,
214-
"greek/αβ": true,
215-
"": false,
216-
"\x00": false,
217-
"\x7f": false,
218-
"a!": false,
219-
"a b": false,
220-
`a\b`: false,
221-
"`a`": false,
222-
"\x80\x80": false,
210+
`"a"`: true,
211+
"`a`": true,
212+
`"a/b"`: true,
213+
`"a.b"`: true,
214+
`"m\x61th"`: true,
215+
`"greek/αβ"`: true,
216+
`""`: false,
217+
218+
// Each of these pairs tests both `` vs "" strings
219+
// and also use of invalid characters spelled out as
220+
// escape sequences and written directly.
221+
// For example `"\x00"` tests import "\x00"
222+
// while "`\x00`" tests import `<actual-NUL-byte>`.
223+
`"\x00"`: false,
224+
"`\x00`": false,
225+
`"\x7f"`: false,
226+
"`\x7f`": false,
227+
`"a!"`: false,
228+
"`a!`": false,
229+
`"a b"`: false,
230+
"`a b`": false,
231+
`"a\\b"`: false,
232+
"`a\\b`": false,
233+
"\"`a`\"": false,
234+
"`\"a\"`": false,
235+
`"\x80\x80"`: false,
236+
"`\x80\x80`": false,
237+
`"\xFFFD"`: false,
238+
"`\xFFFD`": false,
223239
}
224240

225241
func TestImports(t *testing.T) {
226242
for path, isValid := range imports {
227-
src := fmt.Sprintf("package p; import %q", path)
243+
src := fmt.Sprintf("package p; import %s", path)
228244
_, err := ParseFile(fset, "", src, 0)
229245
switch {
230246
case err != nil && isValid:

0 commit comments

Comments
 (0)