Skip to content

Commit

Permalink
test(goast): add test case for resolving struct field types
Browse files Browse the repository at this point in the history
This commit adds a new test case to the GoFullIdentListenerTest file. The test checks the correct resolution of struct field types and function calls within a given Go code snippet. It ensures that the analysis correctly identifies the function name, number of parameters, and the node name of the function call.
  • Loading branch information
phodal committed Nov 12, 2024
1 parent ec8a4f9 commit 586467a
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,43 @@ func (d *Dao) UpdateCapsule() (affect int64, err error) {
println(firstParameter)
assertEquals(firstParameter.TypeValue, "string")
}

@Test
fun shouldResolveStructFieldType() {
@Language("Go")
val code = """
package user
import (
"context"
rcv1 "go-common/app/service/live/rc/api/liverpc/v1"
)
type Dao struct {
walletUrl string
rcClient rcv1.AchvRPCClient
}
func (d *Dao) GetLiveAchieve(ctx context.Context, uid int64) (achieve int64, err error) {
resp, err := d.rcClient.Userstatus(ctx, &rcv1.AchvUserstatusReq{})
if err != nil || resp == nil || resp.Data == nil {
log.Error("[dao.user|GetLiveAchieve] get rc achieve error(%v), uid(%d), resp(%v)", err, uid, resp)
return
}
achieve = resp.Data.Point
return
}
"""

val codeFile = GoAnalyser().analysis(code, "")
val functionCalls = codeFile.DataStructures[0].Functions[0].FunctionCalls

assertEquals(functionCalls.size, 2)

val getExecFunc = functionCalls[0]
assertEquals(getExecFunc.FunctionName, "Userstatus")
assertEquals(getExecFunc.Parameters.size, 2)

assertEquals(getExecFunc.NodeName, "Dao.rcClient")
}
}

0 comments on commit 586467a

Please sign in to comment.