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

Commit

Permalink
Merge pull request emicklei#45 from uber-go/origin-required-groups
Browse files Browse the repository at this point in the history
Support required groups
  • Loading branch information
emicklei authored Jan 3, 2018
2 parents 1ed9ecb + 5d40d9b commit 8caef47
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Group struct {
Name string
Optional bool
Repeated bool
Required bool
Sequence int
Elements []Visitee
}
Expand Down
1 change: 1 addition & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func parseMessageBody(p *Parser, c elementContainer) error {
g.Comment = c.takeLastComment(pos.Line - 1)
g.Optional = prevTok == tOPTIONAL
g.Repeated = prevTok == tREPEATED
g.Required = prevTok == tREQUIRED
if err := g.parse(p); err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,32 @@ func TestRepeatedGroupInMessage(t *testing.T) {
}

}

func TestRequiredGroupInMessage(t *testing.T) {
src := `message SearchResponse {
required group Result = 1 {
required string url = 2;
optional string title = 3;
repeated string snippets = 4;
}
}`
p := newParserOn(src)
p.next() // consume first token
m := new(Message)
err := m.parse(p)
if err != nil {
t.Error(err)
}
if got, want := len(m.Elements), 1; got != want {
t.Logf("%#v", m.Elements)
t.Fatalf("got [%v] want [%v]", got, want)
}
g := m.Elements[0].(*Group)
if got, want := len(g.Elements), 3; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := g.Required, true; got != want {
t.Fatalf("got Required [%v] want [%v]", got, want)
}

}

0 comments on commit 8caef47

Please sign in to comment.