github.com/keysonzzz/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgGoSource/kmgGoParser/kmgGoParser_test.go (about) 1 package kmgGoParser 2 3 import ( 4 "github.com/bronze1man/kmg/kmgConfig" 5 "github.com/bronze1man/kmg/kmgTest" 6 "testing" 7 //"github.com/bronze1man/kmg/kmgDebug" 8 "github.com/bronze1man/kmg/kmgFile" 9 "path/filepath" 10 "strings" 11 ) 12 13 func TestMustParsePackage(ot *testing.T) { 14 pkg := MustParsePackage(kmgConfig.DefaultEnv().GOPATHToString(), "github.com/bronze1man/kmg/kmgGoSource/kmgGoParser/testPackage") 15 kmgTest.Equal(pkg.GetImportList(), []string{"errors", "bytes"}) 16 } 17 18 func TestMustParsePackageFunc(ot *testing.T) { 19 pkg := MustParsePackage(kmgConfig.DefaultEnv().GOPATHToString(), "github.com/bronze1man/kmg/kmgGoSource/kmgGoParser/testPackage/testFunc") 20 kmgTest.Equal(len(pkg.FuncList), 7) 21 } 22 23 func TestParseGoSrc(ot *testing.T) { 24 gopath := "/usr/local/go" 25 goSourcePath := filepath.Join(gopath, "src") 26 dirList := kmgFile.MustGetAllDir(goSourcePath) 27 for _, dir := range dirList { 28 if strings.Contains(dir, "cmd/go/testdata") { 29 continue 30 } 31 dir, err := filepath.Rel(goSourcePath, dir) 32 if err != nil { 33 panic(err) 34 } 35 MustParsePackage(gopath, dir) 36 } 37 } 38 39 func TestParseCurrentProject(ot *testing.T) { 40 gopath := kmgConfig.DefaultEnv().GOPATHToString() 41 goSourcePath := filepath.Join(gopath, "src") 42 dirList := kmgFile.MustGetAllDir(goSourcePath) 43 for _, dir := range dirList { 44 if strings.Contains(dir, "go/loader/testdata") { 45 continue 46 } 47 dir, err := filepath.Rel(goSourcePath, dir) 48 if err != nil { 49 panic(err) 50 } 51 MustParsePackage(gopath, dir) 52 } 53 }