func mustLoadPackage(path string) (*token.FileSet, *doc.Package) {
	// simpleImporter is used by ast.NewPackage.
	simpleImporter := func(imports map[string]*ast.Object, pkgPath string) (*ast.Object, error) {
		pkg := imports[pkgPath]
		if pkg == nil {
			pkgName := pkgPath[strings.LastIndex(pkgPath, "/")+1:]
			pkg = ast.NewObj(ast.Pkg, pkgName)
			pkg.Data = ast.NewScope(nil) // required for or dot-imports
			imports[pkgPath] = pkg
		}
		return pkg, nil
	}

	srcName := filepath.Base(path) + ".go"
	code, err := ioutil.ReadFile(filepath.Join("testdata", srcName))
	if err != nil {
		panic(err)
	}

	fset := token.NewFileSet()
	pkgFiles := make(map[string]*ast.File)
	astFile, _ := parser.ParseFile(fset, srcName, code, parser.ParseComments)
	pkgFiles[srcName] = astFile
	astPkg, _ := ast.NewPackage(fset, pkgFiles, simpleImporter, nil)
	return fset, doc.New(astPkg, path, 0)
}
// Copied from internal/render/render_test.go, with the slight modification of returning the fset.
Copied from internal/render/render_test.go, with the slight modification of returning the fset.
// Copied from internal / render / render_test . go with the slight modification of returning the fset .
func mustLoadPackage(path string) (*token.FileSet, *doc.Package) {
	simpleImporter := func(imports map[string]*ast.Object, pkgPath string) (*ast.Object, error) {
		pkg := imports[pkgPath]
		if pkg == nil {
			pkgName := pkgPath[strings.LastIndex(pkgPath, "/")+1:]
			pkg = ast.NewObj(ast.Pkg, pkgName)
			pkg.Data = ast.NewScope(nil) 
			imports[pkgPath] = pkg
		}
		return pkg, nil
	}
	srcName := filepath.Base(path) + ".go"
	code, err := ioutil.ReadFile(filepath.Join("testdata", srcName))
	if err != nil {
		panic(err)
	}
	fset := token.NewFileSet()
	pkgFiles := make(map[string]*ast.File)
	astFile, _ := parser.ParseFile(fset, srcName, code, parser.ParseComments)
	pkgFiles[srcName] = astFile
	astPkg, _ := ast.NewPackage(fset, pkgFiles, simpleImporter, nil)
	return fset, doc.New(astPkg, path, 0)
}
func mustLoadPackage ( path string ) ( * token . FileSet , * doc . Package ) { simpleImporter := func ( imports map [ string ] * ast . Object , pkgPath string ) ( * ast . Object , error ) { pkg := imports [ pkgPath ] if pkg == nil { pkgName := pkgPath [ strings . LastIndex ( pkgPath , " " ) + 1 : ] pkg = ast . NewObj ( ast . Pkg , pkgName ) pkg . Data = ast . NewScope ( nil ) imports [ pkgPath ] = pkg } return pkg , nil } srcName := filepath . Base ( path ) + " " code , err := ioutil . ReadFile ( filepath . Join ( " " , srcName ) ) if err != nil { panic ( err ) } fset := token . NewFileSet ( ) pkgFiles := make ( map [ string ] * ast . File ) astFile , _ := parser . ParseFile ( fset , srcName , code , parser . ParseComments ) pkgFiles [ srcName ] = astFile astPkg , _ := ast . NewPackage ( fset , pkgFiles , simpleImporter , nil ) return fset , doc . New ( astPkg , path , 0 ) }
Copied from internal/render/render_test.go, with the slight modification of returning the fset.
Copied from internal / render / render_test . go with the slight modification of returning the fset .
// simpleImporter is used by ast.NewPackage. // required for or dot-imports