github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/amino/genproto/comments_test.go (about) 1 package genproto 2 3 import ( 4 "path" 5 "testing" 6 7 "github.com/gnolang/gno/tm2/pkg/amino" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 // message comment 12 type TestMessageName struct { 13 // field comment 1 14 FieldName1 string 15 // field comment 2 16 FieldName2 []uint64 17 } 18 19 // message comment 2 20 type TestMessageName2 struct { 21 // another field comment 22 FieldName string 23 } 24 25 func TestComments(t *testing.T) { 26 pkg := amino.RegisterPackage( 27 amino.NewPackage( 28 "github.com/gnolang/gno/tm2/pkg/amino/genproto", 29 "amino_test", 30 amino.GetCallersDirname(), 31 ).WithTypes( 32 &TestMessageName{}, 33 &TestMessageName2{}, 34 // Add comments from this same source file. 35 ).WithComments(path.Join(amino.GetCallersDirname(), "comments_test.go"))) 36 37 p3c := NewP3Context() 38 p3c.RegisterPackage(pkg) 39 p3c.ValidateBasic() 40 p3doc := p3c.GenerateProto3SchemaForTypes(pkg, pkg.ReflectTypes()...) 41 proto3Schema := p3doc.Print() 42 assert.Equal(t, `syntax = "proto3"; 43 package amino_test; 44 45 option go_package = "github.com/gnolang/gno/tm2/pkg/amino/genproto/pb"; 46 47 // messages 48 // message comment 49 message TestMessageName { 50 // field comment 1 51 string field_name1 = 1 [json_name = "FieldName1"]; 52 // field comment 2 53 repeated uint64 field_name2 = 2 [json_name = "FieldName2"]; 54 } 55 56 // message comment 2 57 message TestMessageName2 { 58 // another field comment 59 string field_name = 1 [json_name = "FieldName"]; 60 }`, proto3Schema) 61 }