未验证 提交 e0d7f484 编写于 作者: P Phodal Huang

test: add test for sql

上级 7d1fbed8
SELECT name, country FROM Websites;
SELECT * FROM Persons;
......@@ -14,7 +14,11 @@ type SqlIdentifierApp struct {
}
func (j *SqlIdentifierApp) AnalysisPath(codeDir string) {
func NewSqlIdentifierApp() SqlIdentifierApp {
return *&SqlIdentifierApp{}
}
func (j *SqlIdentifierApp) AnalysisPath(codeDir string) []SqlNode {
xmlFiles := (*SqlIdentifierApp)(nil).xmlFiles(codeDir)
for _, xmlFile := range xmlFiles {
xmlFile, err := os.Open(xmlFile)
......@@ -30,6 +34,7 @@ func (j *SqlIdentifierApp) AnalysisPath(codeDir string) {
}
}
var infos []SqlNode
files := (*SqlIdentifierApp)(nil).sqlFiles(codeDir)
for index := range files {
file := files[index]
......@@ -40,7 +45,12 @@ func (j *SqlIdentifierApp) AnalysisPath(codeDir string) {
listener := NewSqlIdentifierListener()
antlr.NewParseTreeWalker().Walk(listener, context)
info := listener.GetNodeInfo()
infos = append(infos, info)
}
return infos
}
func (j *SqlIdentifierApp) xmlFiles(codeDir string) []string {
......
package sql
import (
. "github.com/onsi/gomega"
"testing"
)
func TestJavaIdentifierApp_AnalysisPath(t *testing.T) {
g := NewGomegaWithT(t)
identApp := NewSqlIdentifierApp()
results := identApp.AnalysisPath("../../../_fixtures/sql")
g.Expect(len(results)).To(Equal(1))
}
......@@ -9,6 +9,15 @@ type SqlIdentifierListener struct {
parser.BaseSqlListener
}
type SqlNode struct {
}
var sqlNode SqlNode
func init() {
sqlNode = *&SqlNode{}
}
func NewSqlIdentifierListener() *SqlIdentifierListener {
return &SqlIdentifierListener{}
}
......@@ -40,3 +49,7 @@ func (s *SqlIdentifierListener) EnterSelect_core(ctx *parser.Select_coreContext)
}
}
}
func (s *SqlIdentifierListener) GetNodeInfo() SqlNode {
return sqlNode
}
......@@ -2,9 +2,9 @@ package count
import "github.com/phodal/coca/core/models"
func BuildCallMap(cparsedDeps []models.JClassNode) map[string]int {
func BuildCallMap(parserDeps []models.JClassNode) map[string]int {
var projectMethods = make(map[string]bool)
for _, clz := range cparsedDeps {
for _, clz := range parserDeps {
for _, method := range clz.Methods {
projectMethods[clz.Package+"."+clz.Class+"."+method.Name] = true
}
......@@ -12,7 +12,7 @@ func BuildCallMap(cparsedDeps []models.JClassNode) map[string]int {
// TODO: support identify data class
var callMap = make(map[string]int)
for _, clz := range cparsedDeps {
for _, clz := range parserDeps {
for _, call := range clz.MethodCalls {
callMethod := call.Package + "." + call.Class + "." + call.MethodName
if projectMethods[callMethod] {
......
package main
package unused_classes
import (
"encoding/json"
......@@ -11,7 +11,7 @@ import (
var parsedDeps []JClassNode
func main() {
func Refactoring() {
var analysisPackage = ""
file := support.ReadFile("deps.json")
if file == nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册