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

Commit

Permalink
fix issue emicklei#49, option parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
emicklei_kramphub committed Feb 27, 2018
1 parent b22518e commit 93f1d61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (o *Option) parseAggregate(p *Parser) error {
return nil
}
if tRIGHTCURLY == tok {
continue
return nil
}
if tSEMICOLON == tok {
p.nextPut(pos, tok, lit) // allow for inline comment parsing
Expand Down
28 changes: 28 additions & 0 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,31 @@ option Help = { string_field: "value" }; // inline`
t.Fatalf("got [%v] want [%v]", got, want)
}
}

func TestFieldCustomOptions(t *testing.T) {
proto := `foo.bar lots = 1 [foo={hello:1}, bar=2];`
p := newParserOn(proto)
f := newNormalField()
err := f.parse(p)
if err != nil {
t.Fatal(err)
}
if got, want := f.Type, "foo.bar"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := f.Name, "lots"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := len(f.Options), 2; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := f.Options[0].Name, "foo"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := f.Options[1].Name, "bar"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := f.Options[1].Constant.Source, "2"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}

0 comments on commit 93f1d61

Please sign in to comment.