MCPcopy
hub / github.com/cweill/gotests / exprToString

Function exprToString

internal/ai/parser_go.go:249–269  ·  view source on GitHub ↗

exprToString converts an AST expression to its string representation.

(expr ast.Expr)

Source from the content-addressed store, hash-verified

247
248// exprToString converts an AST expression to its string representation.
249func exprToString(expr ast.Expr) string {
250 switch e := expr.(type) {
251 case *ast.BasicLit:
252 return e.Value
253 case *ast.Ident:
254 return e.Name
255 case *ast.UnaryExpr:
256 return e.Op.String() + exprToString(e.X)
257 case *ast.BinaryExpr:
258 return exprToString(e.X) + " " + e.Op.String() + " " + exprToString(e.Y)
259 case *ast.CompositeLit:
260 // For complex types (structs/maps/slices), convert AST back to source code
261 var buf bytes.Buffer
262 if err := printer.Fprint(&buf, token.NewFileSet(), e); err != nil {
263 return "nil" // Fallback on error
264 }
265 return buf.String()
266 default:
267 return "nil"
268 }
269}

Callers 2

parseTestCaseFunction · 0.85
parseArgsStructFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected