@@ -113,6 +113,77 @@ func TestGenerateTypeNameByExp_FuncType(t *testing.T) {
113113 },
114114 "func(context.Context, *primitive.SendResult, error)" ,
115115 },
116+ {
117+ "func with named params ignores names" ,
118+ & dst.FuncType {
119+ Params : & dst.FieldList {List : []* dst.Field {
120+ {Names : []* dst.Ident {dst .NewIdent ("ctx" )}, Type : & dst.SelectorExpr {X : dst .NewIdent ("context" ), Sel : dst .NewIdent ("Context" )}},
121+ {Names : []* dst.Ident {dst .NewIdent ("err" )}, Type : dst .NewIdent ("error" )},
122+ }},
123+ },
124+ "func(context.Context, error)" ,
125+ },
126+ {
127+ "func with multi-name field expands types" ,
128+ & dst.FuncType {
129+ Params : & dst.FieldList {List : []* dst.Field {
130+ {Names : []* dst.Ident {dst .NewIdent ("a" ), dst .NewIdent ("b" )}, Type : dst .NewIdent ("int" )},
131+ {Names : []* dst.Ident {dst .NewIdent ("s" )}, Type : dst .NewIdent ("string" )},
132+ }},
133+ },
134+ "func(int, int, string)" ,
135+ },
136+ {
137+ "func with named single result ignores name" ,
138+ & dst.FuncType {
139+ Params : & dst.FieldList {List : []* dst.Field {
140+ {Type : dst .NewIdent ("int" )},
141+ }},
142+ Results : & dst.FieldList {List : []* dst.Field {
143+ {Names : []* dst.Ident {dst .NewIdent ("err" )}, Type : dst .NewIdent ("error" )},
144+ }},
145+ },
146+ "func(int) error" ,
147+ },
148+ {
149+ "func with named multiple results ignores names" ,
150+ & dst.FuncType {
151+ Params : & dst.FieldList {List : []* dst.Field {
152+ {Type : dst .NewIdent ("int" )},
153+ }},
154+ Results : & dst.FieldList {List : []* dst.Field {
155+ {Names : []* dst.Ident {dst .NewIdent ("n" )}, Type : dst .NewIdent ("int" )},
156+ {Names : []* dst.Ident {dst .NewIdent ("err" )}, Type : dst .NewIdent ("error" )},
157+ }},
158+ },
159+ "func(int) (int, error)" ,
160+ },
161+ {
162+ "func with multi-name result field expands types" ,
163+ & dst.FuncType {
164+ Params : & dst.FieldList {List : []* dst.Field {
165+ {Type : dst .NewIdent ("string" )},
166+ }},
167+ Results : & dst.FieldList {List : []* dst.Field {
168+ {Names : []* dst.Ident {dst .NewIdent ("x" ), dst .NewIdent ("y" )}, Type : dst .NewIdent ("int" )},
169+ }},
170+ },
171+ "func(string) (int, int)" ,
172+ },
173+ {
174+ "func with named params and results from real code" ,
175+ & dst.FuncType {
176+ Params : & dst.FieldList {List : []* dst.Field {
177+ {Names : []* dst.Ident {dst .NewIdent ("ctx" )}, Type : & dst.SelectorExpr {X : dst .NewIdent ("context" ), Sel : dst .NewIdent ("Context" )}},
178+ {Names : []* dst.Ident {dst .NewIdent ("req" )}, Type : & dst.StarExpr {X : & dst.SelectorExpr {X : dst .NewIdent ("http" ), Sel : dst .NewIdent ("Request" )}}},
179+ }},
180+ Results : & dst.FieldList {List : []* dst.Field {
181+ {Names : []* dst.Ident {dst .NewIdent ("resp" )}, Type : & dst.StarExpr {X : & dst.SelectorExpr {X : dst .NewIdent ("http" ), Sel : dst .NewIdent ("Response" )}}},
182+ {Names : []* dst.Ident {dst .NewIdent ("err" )}, Type : dst .NewIdent ("error" )},
183+ }},
184+ },
185+ "func(context.Context, *http.Request) (*http.Response, error)" ,
186+ },
116187 }
117188 for _ , tt := range tests {
118189 t .Run (tt .name , func (t * testing.T ) {
0 commit comments