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

Commit

Permalink
Additional tests for complex options (emicklei#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored and emicklei committed Mar 3, 2018
1 parent 6eb67ab commit 8ac4c5b
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,102 @@ func TestNestedAggregateConstants(t *testing.T) {
t.Errorf("got [%v] want [%v]", got, want)
}
}

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 }
}
};`
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)
}
}

0 comments on commit 8ac4c5b

Please sign in to comment.