From 581110db3e291016c1dc116289492ffa73f7192d Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Sat, 3 Mar 2018 08:51:47 +0100 Subject: [PATCH] Issue59 (#67) * 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 --- option.go | 6 +++ option_test.go | 104 +++++++------------------------------------------ 2 files changed, 21 insertions(+), 89 deletions(-) diff --git a/option.go b/option.go index 92bbf84..475084f 100644 --- a/option.go +++ b/option.go @@ -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 diff --git a/option_test.go b/option_test.go index b7c1ba9..b892d7c 100644 --- a/option_test.go +++ b/option_test.go @@ -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) } }