Skip to content

Commit

Permalink
feat: support inline c style comments in fields (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice authored Feb 12, 2024
1 parent eb3ff50 commit ac27b42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/nilslice/protolock
go 1.21

require (
github.com/emicklei/proto v1.9.1
github.com/emicklei/proto v1.13.2
github.com/extism/go-sdk v1.0.0
github.com/stretchr/testify v1.8.4
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/proto v1.9.1 h1:MUgjFo5xlMwYv72TnF5xmmdKZ04u+dVbv6wdARv16D8=
github.com/emicklei/proto v1.9.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY=
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/extism/go-sdk v1.0.0 h1://UAyiQGok1ihrlzpkfF6UTY5TwJs6hKJBXnQ0sui20=
github.com/extism/go-sdk v1.0.0/go.mod h1:xUfKSEQndAvHBc1Ohdre0e+UdnRzUpVfbA8QLcx4fbY=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
Expand Down
29 changes: 29 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ message Channel {
}
`

const protoWithCStyleInlineComments = `
syntax = "proto3";
message Example {
optional /* i'm a comment */ bool field = 1;
}
`

var gpfPath = filepath.Join("testdata", "getProtoFiles")

func TestParseSingleQuoteReservedNames(t *testing.T) {
Expand Down Expand Up @@ -503,3 +511,24 @@ func TestGetProtoFilesIgnoresMultiple(t *testing.T) {
path = filepath.Join(gpfPath, "include", "include.proto")
assert.Contains(t, files, path)
}

func TestCStyleInlineComments(t *testing.T) {
r := strings.NewReader(protoWithCStyleInlineComments)

entry, err := Parse("test:protoWithCStyleInlineComments", r)
assert.NoError(t, err)
assert.Len(t, entry.Messages, 1)

example := entry.Messages[0]
assert.Len(t, example.Fields, 1)
assert.Equal(t, example.Name, "Example")

// message Example {
// optional /* i'm a comment */ bool field = 1;
// }

field := example.Fields[0]
assert.Equal(t, field.Name, "field")
assert.Equal(t, field.Type, "bool")
assert.True(t, field.IsOptional)
}

0 comments on commit ac27b42

Please sign in to comment.