From e62f83bb7e97c15d57b1404ee6d9ada218e81d80 Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Tue, 7 Feb 2017 13:40:59 +0100 Subject: [PATCH] fix missing semicolon for oneof field Change-Id: Idafbb735272cbe141d86e05b488ecc66f13e79d0 --- formatter_test.go | 2 +- oneof.go | 15 +++++++++++++++ option.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/formatter_test.go b/formatter_test.go index 1c2b421..3e4cc5a 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -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 { diff --git a/oneof.go b/oneof.go index 5ff71ca..9c870ce 100644 --- a/oneof.go +++ b/oneof.go @@ -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 { @@ -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 @@ -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 } diff --git a/option.go b/option.go index d601dea..64a3105 100644 --- a/option.go +++ b/option.go @@ -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())) }