func TestCompatible(t *testing.T) { expect := gspec.Expect(t.FailNow) srcList := []string{ "compatible_test.go", } for _, srcFile := range srcList { fset := token.NewFileSet() stdAst, stdErr := std.ParseFile(fset, srcFile, nil, std.ParseComments) fset = token.NewFileSet() gomAst, gomErr := gom.ParseFile(fset, srcFile, nil, gom.ParseComments) expect("parse error", gomErr).Equal(stdErr) //expect("decl count", len(gomAst.Decls)).Equal(len(stdAst.Decls)) //fmt.Println(gomAst.Decls[1].(*ast.FuncDecl).Type.Results) //fmt.Println(stdAst.Decls[1].(*ast.FuncDecl).Type.Results) for i := range stdAst.Decls { expect(astStr(gomAst.Decls[i], fset)).Equal(astStr(stdAst.Decls[i], fset)) } expect(astStr(gomAst, fset)).Equal(astStr(stdAst, fset)) } }
func ExampleParseFile() { fset := token.NewFileSet() // positions are relative to fset // Parse the file containing this very example // but stop after processing the imports. f, err := parser.ParseFile(fset, "example_test.go", nil, parser.ImportsOnly) if err != nil { fmt.Println(err) return } // Print the imports from the file's AST. for _, s := range f.Imports { fmt.Println(s.Path.Value) } // output: // // "fmt" // "go/token" // "github.com/hailiang/gombi/lib/go/parser" }