-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: In amino/pkg, add optional WithComments, use them in GenerateP…
…roto3MessagePartial Signed-off-by: Jeff Thompson <[email protected]>
- Loading branch information
Showing
3 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package genproto | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/amino" | ||
"github.com/jaekwon/testify/assert" | ||
) | ||
|
||
// message comment | ||
type TestMessageName struct { | ||
// field comment 1 | ||
FieldName1 string | ||
// field comment 2 | ||
FieldName2 []uint64 | ||
} | ||
|
||
// message comment 2 | ||
type TestMessageName2 struct { | ||
// another field comment | ||
FieldName string | ||
} | ||
|
||
func TestComments(t *testing.T) { | ||
pkg := amino.RegisterPackage( | ||
amino.NewPackage( | ||
"github.com/gnolang/gno/tm2/pkg/amino/genproto", | ||
"amino_test", | ||
amino.GetCallersDirname(), | ||
).WithTypes( | ||
&TestMessageName{}, | ||
&TestMessageName2{}, | ||
// Add comments from this same source file. | ||
).WithComments(path.Join(amino.GetCallersDirname(), "comments_test.go"))) | ||
|
||
p3c := NewP3Context() | ||
p3c.RegisterPackage(pkg) | ||
p3c.ValidateBasic() | ||
p3doc := p3c.GenerateProto3SchemaForTypes(pkg, pkg.ReflectTypes()...) | ||
proto3Schema := p3doc.Print() | ||
assert.Equal(t, proto3Schema, `syntax = "proto3"; | ||
package amino_test; | ||
option go_package = "github.com/gnolang/gno/tm2/pkg/amino/genproto/pb"; | ||
// messages | ||
// message comment | ||
message TestMessageName { | ||
// field comment 1 | ||
string FieldName1 = 1; | ||
// field comment 2 | ||
repeated uint64 FieldName2 = 2; | ||
} | ||
// message comment 2 | ||
message TestMessageName2 { | ||
// another field comment | ||
string FieldName = 1; | ||
}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters