package matching import ( "os" "strings" "testing" ) func readFile(t *testing.T, name string) string { t.Helper() b, err := os.ReadFile(name) if err != nil { t.Fatalf("read %s: %v", name, err) } return string(b) } // functionBody bounds one function's text for the structural guards. Crude, and sufficient: it only has to // find where a function ends, and gofmt guarantees a top level func starts at column zero. func functionBody(src, signature string) string { i := strings.Index(src, signature) if i < 0 { return "" } rest := src[i+len(signature):] if j := strings.Index(rest, "\nfunc "); j >= 0 { return rest[:j] } return rest }