Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
fix missing semicolon for oneof field
Browse files Browse the repository at this point in the history
Change-Id: Idafbb735272cbe141d86e05b488ecc66f13e79d0
  • Loading branch information
emicklei committed Feb 7, 2017
1 parent 838d00d commit e62f83b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestPrintListOfColumns(t *testing.T) {
b := new(bytes.Buffer)
f := NewFormatter(b, " ")
f.printListOfColumns(list, "enum")
formatted := `A = 1 [a = 1234];
formatted := `A = 1 [a = 1234];
ABC = 12 [ab = 1234];
`
if got, want := b.String(), formatted; got != want {
Expand Down
15 changes: 15 additions & 0 deletions oneof.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ type Oneof struct {
Elements []Visitee
}

// addElement is part of elementContainer
func (o *Oneof) addElement(v Visitee) {
o.Elements = append(o.Elements, v)
}

// elements is part of elementContainer
func (o *Oneof) elements() []Visitee {
return o.Elements
}

// parse expects:
// oneofName "{" { oneofField | emptyStatement } "}"
func (o *Oneof) parse(p *Parser) error {
Expand Down Expand Up @@ -39,6 +49,7 @@ func (o *Oneof) parse(p *Parser) error {
}
o.Elements = append(o.Elements, g)
case tSEMICOLON:
maybeScanInlineComment(p, o)
// continue
default:
goto done
Expand Down Expand Up @@ -86,5 +97,9 @@ func (o *OneOfField) columns() (cols []aligned) {
}
cols = append(cols, leftAligned("]"))
}
cols = append(cols, alignedSemicolon)
if o.Comment != nil {
cols = append(cols, notAligned(" //"), notAligned(o.Comment.Message))
}
return
}
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (o *Option) keyValuePair(embedded bool) (cols []aligned) {
equals := alignedEquals
name := o.Name
if embedded {
return append(cols, notAligned(name), equals, rightAligned(o.Constant.String()))
return append(cols, leftAligned(name), equals, leftAligned(o.Constant.String())) // numbers right, strings left? TODO
}
return append(cols, rightAligned(name), equals, rightAligned(o.Constant.String()))
}
Expand Down

0 comments on commit e62f83b

Please sign in to comment.