unit test for the proposed change, fails before the change, succeeds after the change

This commit is contained in:
David Tolpin 2018-11-01 19:02:46 +02:00
parent ab3239aa9a
commit 093d5de35b
1 changed files with 35 additions and 0 deletions

View File

@ -736,3 +736,38 @@ func TestIssue11151(t *testing.T) {
t.Errorf("%v\norig: %q\ngot : %q", err, src, got)
}
}
// If a declaration has multiple specifications, a parenthesized
// declaration must be printed even if Lparen is token.NoPos.
func TestParenthesizedDecl(t *testing.T) {
// a package with multiple specs in a single declaration
const src = "package p; var ( a float64; b int )"
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "", src, 0)
// reset the file set to get uniform formatting
fset = token.NewFileSet()
var buf bytes.Buffer
// Print the original package
err = Fprint(&buf, fset, f)
if err != nil {
t.Fatal(err)
}
original := buf.String()
// Now remove parentheses from the declaration
for i := 0; i != len(f.Decls); i++ {
f.Decls[i].(*ast.GenDecl).Lparen = token.NoPos
}
buf.Reset()
err = Fprint(&buf, fset, f)
if err != nil {
t.Fatal(err)
}
noparen := buf.String()
if noparen != original {
t.Errorf("got %q, want %q", noparen, original)
}
}