1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:14:40 -07:00

go/printer, gofmt: fix formatting of expression lists (missing blank)

This appears to have been a long-standing formatting bug.
The test cases has misformatted golden files.

Applied gofmt -w src misc .

Fixes #1839.

R=iant
CC=golang-dev
https://golang.org/cl/4515113
This commit is contained in:
Robert Griesemer 2011-05-19 17:05:35 -07:00
parent 2f5a77cd5e
commit b790ae2efb
8 changed files with 36 additions and 34 deletions

View File

@ -59,7 +59,7 @@ func dash(meth, cmd string, resp interface{}, args param) os.Error {
func dashStatus(meth, cmd string, args param) os.Error { func dashStatus(meth, cmd string, args param) os.Error {
var resp struct { var resp struct {
Status string Status string
Error string Error string
} }
err := dash(meth, cmd, &resp, args) err := dash(meth, cmd, &resp, args)
if err != nil { if err != nil {
@ -73,7 +73,7 @@ func dashStatus(meth, cmd string, args param) os.Error {
// todo returns the next hash to build. // todo returns the next hash to build.
func (b *Builder) todo() (rev string, err os.Error) { func (b *Builder) todo() (rev string, err os.Error) {
var resp []struct{ var resp []struct {
Hash string Hash string
} }
if err = dash("GET", "todo", &resp, param{"builder": b.name}); err != nil { if err = dash("GET", "todo", &resp, param{"builder": b.name}); err != nil {
@ -128,12 +128,12 @@ func (b *Builder) updatePackage(pkg string, state bool, buildLog, info string, h
// postCommit informs the dashboard of a new commit // postCommit informs the dashboard of a new commit
func postCommit(key string, l *HgLog) os.Error { func postCommit(key string, l *HgLog) os.Error {
return dashStatus("POST", "commit", param{ return dashStatus("POST", "commit", param{
"key": key, "key": key,
"node": l.Hash, "node": l.Hash,
"date": l.Date, "date": l.Date,
"user": l.Author, "user": l.Author,
"parent": l.Parent, "parent": l.Parent,
"desc": l.Desc, "desc": l.Desc,
}) })
} }

View File

@ -48,7 +48,7 @@ type Builder struct {
var ( var (
buildroot = flag.String("buildroot", path.Join(os.TempDir(), "gobuilder"), "Directory under which to build") buildroot = flag.String("buildroot", path.Join(os.TempDir(), "gobuilder"), "Directory under which to build")
commitFlag = flag.Bool("commit", false, "upload information about new commits") commitFlag = flag.Bool("commit", false, "upload information about new commits")
dashboard = flag.String("dashboard", "godashboard.appspot.com", "Go Dashboard Host") dashboard = flag.String("dashboard", "godashboard.appspot.com", "Go Dashboard Host")
buildRelease = flag.Bool("release", false, "Build and upload binary release archives") buildRelease = flag.Bool("release", false, "Build and upload binary release archives")
buildRevision = flag.String("rev", "", "Build specified revision and exit") buildRevision = flag.String("rev", "", "Build specified revision and exit")
@ -389,10 +389,10 @@ func commitWatcher() {
// HgLog represents a single Mercurial revision. // HgLog represents a single Mercurial revision.
type HgLog struct { type HgLog struct {
Hash string Hash string
Author string Author string
Date string Date string
Desc string Desc string
Parent string Parent string
// Internal metadata // Internal metadata
@ -430,12 +430,12 @@ func commitPoll(key string) {
return return
} }
const N = 20 // how many revisions to grab const N = 20 // how many revisions to grab
data, _, err := runLog(nil, "", goroot, "hg", "log", data, _, err := runLog(nil, "", goroot, "hg", "log",
"--encoding=utf-8", "--encoding=utf-8",
"--limit=" + strconv.Itoa(N), "--limit="+strconv.Itoa(N),
"--template=" + xmlLogTemplate, "--template="+xmlLogTemplate,
) )
if err != nil { if err != nil {
log.Printf("hg log: %v", err) log.Printf("hg log: %v", err)
@ -445,7 +445,7 @@ func commitPoll(key string) {
var logStruct struct { var logStruct struct {
Log []HgLog Log []HgLog
} }
err = xml.Unmarshal(strings.NewReader("<top>" + data + "</top>"), &logStruct) err = xml.Unmarshal(strings.NewReader("<top>"+data+"</top>"), &logStruct)
if err != nil { if err != nil {
log.Printf("unmarshal hg log: %v", err) log.Printf("unmarshal hg log: %v", err)
return return

View File

@ -215,12 +215,13 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp
} }
if i > 0 { if i > 0 {
if mode&commaSep != 0 { switch {
case mode&commaSep != 0:
p.print(token.COMMA) p.print(token.COMMA)
} case mode&periodSep != 0:
if mode&periodSep != 0 {
p.print(token.PERIOD) p.print(token.PERIOD)
} }
needsBlank := mode&periodSep == 0 // period-separated list elements don't need a blank
if prevLine < line && prevLine > 0 && line > 0 { if prevLine < line && prevLine > 0 && line > 0 {
// lines are broken using newlines so comments remain aligned // lines are broken using newlines so comments remain aligned
// unless forceFF is set or there are multiple expressions on // unless forceFF is set or there are multiple expressions on
@ -229,11 +230,12 @@ func (p *printer) exprList(prev0 token.Pos, list []ast.Expr, depth int, mode exp
ws = ignore ws = ignore
*multiLine = true *multiLine = true
prevBreak = i prevBreak = i
needsBlank = false // we got a line break instead
} }
} else if mode&periodSep == 0 { }
if needsBlank {
p.print(blank) p.print(blank)
} }
// period-separated list elements don't need a blank
} }
if isPair && size > 0 && len(list) > 1 { if isPair && size > 0 && len(list) > 1 {

View File

@ -644,7 +644,7 @@ func _() {
func f() { func f() {
// os.Open parameters should remain on two lines // os.Open parameters should remain on two lines
if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE| if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
os.O_TRUNC,0666); err != nil { os.O_TRUNC, 0666); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -644,7 +644,7 @@ func _() {
func f() { func f() {
// os.Open parameters should remain on two lines // os.Open parameters should remain on two lines
if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE| if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
os.O_TRUNC,0666); err != nil { os.O_TRUNC, 0666); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -624,7 +624,7 @@ func TestServerConsumesRequestBody(t *testing.T) {
"POST / HTTP/1.1\r\n"+ "POST / HTTP/1.1\r\n"+
"Host: test\r\n"+ "Host: test\r\n"+
"Content-Length: %d\r\n"+ "Content-Length: %d\r\n"+
"\r\n",len(body)))) "\r\n", len(body))))
conn.readBuf.Write([]byte(body)) conn.readBuf.Write([]byte(body))
done := make(chan bool) done := make(chan bool)

View File

@ -315,7 +315,7 @@ foo: bar
--MyBoundary-- --MyBoundary--
`,"\n", "\r\n", -1) `, "\n", "\r\n", -1)
r := NewReader(strings.NewReader(testBody), "MyBoundary") r := NewReader(strings.NewReader(testBody), "MyBoundary")
part, err := r.NextPart() part, err := r.NextPart()
if err != nil { if err != nil {

View File

@ -56,6 +56,6 @@ func TestLookup(t *testing.T) {
if !reflect.DeepEqual(u, un) { if !reflect.DeepEqual(u, un) {
t.Errorf("Lookup by userid vs. name didn't match\n"+ t.Errorf("Lookup by userid vs. name didn't match\n"+
"LookupId(%d): %#v\n"+ "LookupId(%d): %#v\n"+
"Lookup(%q): %#v\n",uid, u, u.Username, un) "Lookup(%q): %#v\n", uid, u, u.Username, un)
} }
} }