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

Commit

Permalink
Issue47 (emicklei#57)
Browse files Browse the repository at this point in the history
* fix issue47 : inline comment for rpc without option or stat
  • Loading branch information
emicklei authored Jan 12, 2018
1 parent 92f8274 commit e122c20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (s *Service) parse(p *Parser) error {
return err
}
s.Elements = append(s.Elements, rpc)
maybeScanInlineComment(p, s)
case tSEMICOLON:
maybeScanInlineComment(p, s)
case tRIGHTCURLY:
Expand Down
21 changes: 18 additions & 3 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import "testing"
func TestService(t *testing.T) {
proto := `service AccountService {
// comment
rpc CreateAccount (CreateAccount) returns (ServiceFault);
rpc GetAccounts (stream Int64) returns (Account);
rpc Health(google.protobuf.Empty) returns (google.protobuf.Empty) {}
rpc CreateAccount (CreateAccount) returns (ServiceFault); // inline comment
rpc GetAccounts (stream Int64) returns (Account) {} // inline comment2
rpc Health(google.protobuf.Empty) returns (google.protobuf.Empty) {} // inline comment3
}`
pr, err := newParserOn(proto).Parse()
if err != nil {
Expand All @@ -50,6 +50,9 @@ func TestService(t *testing.T) {
if got, want := rpc1.Doc().Message(), " comment"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc1.InlineComment.Message(), " inline comment"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if got, want := rpc1.Position.Line, 3; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
Expand All @@ -61,6 +64,18 @@ func TestService(t *testing.T) {
if got, want := rpc3.Name, "Health"; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
if rpc2.InlineComment == nil {
t.Fatal("missing inline comment 2")
}
if got, want := rpc2.InlineComment.Message(), " inline comment2"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
if rpc3.InlineComment == nil {
t.Fatal("missing inline comment 3")
}
if got, want := rpc3.InlineComment.Message(), " inline comment3"; got != want {
t.Fatalf("got [%v] want [%v]", got, want)
}
}

func TestRPCWithOptionAggregateSyntax(t *testing.T) {
Expand Down

0 comments on commit e122c20

Please sign in to comment.