MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / testValueForExpr

Function testValueForExpr

types/source_test.go:232–326  ·  view source on GitHub ↗
(t *testing.T, testfile string)

Source from the content-addressed store, hash-verified

230}
231
232func testValueForExpr(t *testing.T, testfile string) {
233 if runtime.GOOS == "android" {
234 t.Skipf("no testdata dir on %s", runtime.GOOS)
235 }
236
237 conf := loader.Config{ParserMode: parser.ParseComments}
238 f, err := conf.ParseFile(testfile, nil)
239 if err != nil {
240 t.Error(err)
241 return
242 }
243 conf.CreateFromFiles("main", f)
244
245 iprog, err := conf.Load()
246 if err != nil {
247 t.Error(err)
248 return
249 }
250
251 mainInfo := iprog.Created[0]
252
253 prog := ssautil.CreateProgram(iprog, 0)
254 mainPkg := prog.Package(mainInfo.Pkg)
255 mainPkg.SetDebugMode(true)
256 mainPkg.Build()
257
258 if false {
259 // debugging
260 for _, mem := range mainPkg.Members {
261 if fn, ok := mem.(*types.Function); ok {
262 fn.WriteTo(os.Stderr)
263 }
264 }
265 }
266
267 var parenExprs []*ParenExpr
268 Inspect(f, func(n Node) bool {
269 if n != nil {
270 if e, ok := n.(*ParenExpr); ok {
271 parenExprs = append(parenExprs, e)
272 }
273 }
274 return true
275 })
276
277 notes, err := expect.ExtractGo(prog.Fset, f)
278 if err != nil {
279 t.Fatal(err)
280 }
281 for _, n := range notes {
282 want := n.Name
283 if want == "nil" {
284 want = "<nil>"
285 }
286 position := n.Pos
287 var e Expr
288 for _, paren := range parenExprs {
289 if paren.Pos() > n.Pos {

Callers 2

TestValueForExprFunction · 0.85

Calls 15

ParseFileMethod · 0.95
CreateFromFilesMethod · 0.95
LoadMethod · 0.95
CreateProgramFunction · 0.92
InspectFunction · 0.85
IdenticalFunction · 0.85
TypeOfMethod · 0.80
PosMethod · 0.65
TypeMethod · 0.65
ElemMethod · 0.65
UnderlyingMethod · 0.65
appendFunction · 0.50

Tested by

no test coverage detected