Skip to content

Commit

Permalink
Issue59 (#67)
Browse files Browse the repository at this point in the history
* add multiline test for issue #59

* concat multiple aggregate string constants, issue #59

* fix issue 50

* Additional tests for complex options (#65)

* add multiline test for issue #59

* concat multiple aggregate string constants, issue #59
  • Loading branch information
emicklei authored Mar 3, 2018
1 parent 8ac4c5b commit 581110d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 89 deletions.
6 changes: 6 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func parseAggregateConstants(p *Parser, container interface{}) (list []*NamedLit
err = p.unexpected(lit, "option aggregate key", container)
return
}
// workaround issue #59 TODO
if isString(lit) && len(list) > 0 {
// concatenate with previous constant
list[len(list)-1].Source += unQuote(lit)
continue
}
key := lit
printsColon := false
// expect colon, aggregate or plain literal
Expand Down
104 changes: 15 additions & 89 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,101 +295,27 @@ func TestNestedAggregateConstants(t *testing.T) {
}
}

func TestNestedAggregateConstantsColons(t *testing.T) {
src := `syntax = "proto3";
package baz;
option (foo.bar) = {
woot: 100
foo: {
hello: 200
hello2: 300
bar: {
hello3: 400
}
}
};`
p := newParserOn(src)
proto, err := p.Parse()
if err != nil {
t.Error(err)
}
option := proto.Elements[2].(*Option)
if got, want := option.Name, "(foo.bar)"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := len(option.AggregatedConstants), 4; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[0].Name, "woot"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[1].Name, "foo.hello"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[2].Name, "foo.hello2"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[3].Name, "foo.bar.hello3"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[1].Literal.SourceRepresentation(), "200"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[2].Literal.SourceRepresentation(), "300"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[3].Literal.SourceRepresentation(), "400"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}

func TestNestedAggregateConstantsColonsWithLineSeparation(t *testing.T) {
src := `syntax = "proto3";
package baz;
option (foo.bar) = {
woot: 100
foo: {
hello: 200
hello2: 300
bar:
{ hello3: 400 }
}
};`
// Issue #59
func TestMultiLineOptionAggregateValue(t *testing.T) {
src := `rpc ListTransferLogs(ListTransferLogsRequest)
returns (ListTransferLogsResponse) {
option (google.api.http) = {
get: "/v1/{parent=projects/*/locations/*/transferConfigs/*/runs/*}/"
"transferLogs"
};
}`
p := newParserOn(src)
proto, err := p.Parse()
rpc := new(RPC)
p.next()
err := rpc.parse(p)
if err != nil {
t.Error(err)
}
option := proto.Elements[2].(*Option)
if got, want := option.Name, "(foo.bar)"; got != want {
get := rpc.Options[0].AggregatedConstants[0]
if got, want := get.Name, "get"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := len(option.AggregatedConstants), 4; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[0].Name, "woot"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[1].Name, "foo.hello"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[2].Name, "foo.hello2"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[3].Name, "foo.bar.hello3"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[1].Literal.SourceRepresentation(), "200"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[2].Literal.SourceRepresentation(), "300"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if got, want := option.AggregatedConstants[3].Literal.SourceRepresentation(), "400"; got != want {
if got, want := get.Literal.Source, "/v1/{parent=projects/*/locations/*/transferConfigs/*/runs/*}/transferLogs"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}

0 comments on commit 581110d

Please sign in to comment.