@@ -22,6 +22,7 @@ type queryDefinitionTestCase struct {
2222 clientId string
2323 codebasePath string
2424 filePath string
25+ symbolName string
2526 startLine int
2627 endLine int
2728 expectedStatus int
@@ -132,6 +133,82 @@ func (s *QueryDefinitionIntegrationTestSuite) TestQueryDefinition() {
132133 assert .False (t , response ["success" ].(bool ))
133134 },
134135 },
136+ {
137+ name : "单符号查询-成功查询函数定义" ,
138+ clientId : "123" ,
139+ codebasePath : s .workspacePath ,
140+ symbolName : "TestQueryDefinition" ,
141+ expectedStatus : http .StatusOK ,
142+ expectedCode : "0" ,
143+ validateResp : func (t * testing.T , response map [string ]interface {}) {
144+ assert .True (t , response ["success" ].(bool ))
145+ assert .Equal (t , "ok" , response ["message" ])
146+
147+ data := response ["data" ].(map [string ]interface {})
148+ list := data ["list" ].([]interface {})
149+ assert .GreaterOrEqual (t , len (list ), 0 )
150+
151+ // 如果找到结果,验证结构
152+ if len (list ) > 0 {
153+ firstItem := list [0 ].(map [string ]interface {})
154+ assert .Contains (t , firstItem , "filePath" )
155+ assert .Contains (t , firstItem , "name" )
156+ assert .Contains (t , firstItem , "type" )
157+ assert .Contains (t , firstItem , "content" )
158+ assert .Contains (t , firstItem , "position" )
159+
160+ // 验证符号名称匹配
161+ assert .Equal (t , "TestQueryDefinition" , firstItem ["name" ])
162+
163+ position := firstItem ["position" ].(map [string ]interface {})
164+ assert .Contains (t , position , "startLine" )
165+ assert .Contains (t , position , "startColumn" )
166+ assert .Contains (t , position , "endLine" )
167+ assert .Contains (t , position , "endColumn" )
168+
169+ // 验证类型字段的有效值
170+ validTypes := []string {"variable" , "definition.function" , "definition.method" , "definition.class" }
171+ assert .Contains (t , validTypes , firstItem ["type" ])
172+ }
173+ },
174+ },
175+ {
176+ name : "单符号查询-不存在的符号" ,
177+ clientId : "123" ,
178+ codebasePath : s .workspacePath ,
179+ symbolName : "NonExistentSymbol12345" ,
180+ expectedStatus : http .StatusOK ,
181+ expectedCode : "0" ,
182+ validateResp : func (t * testing.T , response map [string ]interface {}) {
183+ assert .True (t , response ["success" ].(bool ))
184+ assert .Equal (t , "ok" , response ["message" ])
185+
186+ data := response ["data" ].(map [string ]interface {})
187+ // 这里是空的
188+ list := data ["list" ]
189+ assert .Nil (t , list )
190+ // 不存在的符号应该返回空列表
191+ },
192+ },
193+ {
194+ name : "单符号查询-缺少codebasePath参数" ,
195+ clientId : "123" ,
196+ symbolName : "TestQueryDefinition" ,
197+ expectedStatus : http .StatusBadRequest ,
198+ validateResp : func (t * testing.T , response map [string ]interface {}) {
199+ assert .False (t , response ["success" ].(bool ))
200+ },
201+ },
202+ {
203+ name : "单符号查询-空符号名" ,
204+ clientId : "123" ,
205+ codebasePath : s .workspacePath ,
206+ symbolName : "" ,
207+ expectedStatus : http .StatusBadRequest ,
208+ validateResp : func (t * testing.T , response map [string ]interface {}) {
209+ assert .False (t , response ["success" ].(bool ))
210+ },
211+ },
135212 }
136213
137214 // 执行表格驱动测试
@@ -152,6 +229,9 @@ func (s *QueryDefinitionIntegrationTestSuite) TestQueryDefinition() {
152229 if tc .filePath != "" {
153230 q .Add ("filePath" , tc .filePath )
154231 }
232+ if tc .symbolName != "" {
233+ q .Add ("symbolName" , tc .symbolName )
234+ }
155235 if tc .startLine > 0 {
156236 q .Add ("startLine" , fmt .Sprintf ("%d" , tc .startLine ))
157237 }
0 commit comments