Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
cd9f1427
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
cd9f1427
编写于
1月 06, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: add git reset for refactor test
上级
6f6729ad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
31 deletion
+40
-31
_fixtures/refactor/rename.config
_fixtures/refactor/rename.config
+1
-1
cocatest/git_reset.go
cocatest/git_reset.go
+18
-0
core/context/refactor/rename/rename_method_test.go
core/context/refactor/rename/rename_method_test.go
+9
-29
core/context/refactor/unused/remove_unused_import_test.go
core/context/refactor/unused/remove_unused_import_test.go
+12
-1
未找到文件。
_fixtures/refactor/rename.config
浏览文件 @
cd9f1427
polymorphism
.
Overload
.
demo
->
polymorphism
.
Overload
.
demoA
polymorphism
.
Overload
.
demo
A
->
polymorphism
.
Overload
.
demo
cocatest/git_reset.go
0 → 100644
浏览文件 @
cd9f1427
package
cocatest
import
(
"fmt"
"log"
"os/exec"
)
func
ResetGitDir
(
codePath
string
)
{
cmd
:=
exec
.
Command
(
"git"
,
"checkout"
,
"--ignore-skip-worktree-bits"
,
"--"
,
codePath
)
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
fmt
.
Println
(
string
(
out
))
log
.
Fatalf
(
"cmd.Run() failed with %s
\n
"
,
err
)
}
}
core/context/refactor/rename/rename_method_test.go
浏览文件 @
cd9f1427
package
unused
import
(
"fmt"
.
"github.com/onsi/gomega"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/cocatest"
"github.com/phodal/coca/core/context/analysis"
"path/filepath"
"sync"
"testing"
)
func
TestRenameMethodApp
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
var
wg
sync
.
WaitGroup
codePath
:=
"../../../../_fixtures/refactor/unused"
configPath
:=
"../../../../_fixtures/refactor/rename.config"
codePath
=
filepath
.
FromSlash
(
codePath
)
...
...
@@ -25,35 +25,15 @@ func TestRenameMethodApp(t *testing.T) {
classes
=
append
(
classes
,
node
.
Package
+
"."
+
node
.
ClassName
)
}
wg
.
Add
(
1
)
callApp
:=
analysis
.
NewJavaFullApp
()
callNodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
wg
.
Add
(
1
)
go
func
()
{
RenameMethodApp
(
callNodes
)
.
Refactoring
(
""
)
defer
wg
.
Done
()
newnodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
g
.
Expect
(
newnodes
[
0
]
.
Methods
[
0
]
.
Name
)
.
To
(
Equal
(
"demoA"
))
}()
wg
.
Add
(
1
)
go
func
()
{
wg
.
Wait
()
configPath2
:=
"../../../../_fixtures/refactor/rename_back.config"
configPath2
=
filepath
.
FromSlash
(
configPath2
)
RenameMethodApp
(
callNodes
)
.
Refactoring
(
""
)
defer
wg
.
Done
()
renameBackNodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
g
.
Expect
(
renameBackNodes
[
0
]
.
Methods
[
0
]
.
Name
)
.
To
(
Equal
(
"demo"
))
fmt
.
Println
(
callNodes
)
configBytes
:=
cmd_util
.
ReadFile
(
configPath
)
RenameMethodApp
(
callNodes
)
.
Refactoring
(
string
(
configBytes
))
wg
.
Wait
(
)
}(
)
newnodes
:=
callApp
.
AnalysisPath
(
codePath
,
classes
,
identifiers
)
g
.
Expect
(
newnodes
[
0
]
.
Methods
[
0
]
.
Name
)
.
To
(
Equal
(
"demo"
)
)
cocatest
.
ResetGitDir
(
codePath
)
}
core/context/refactor/unused/remove_unused_import_test.go
浏览文件 @
cd9f1427
...
...
@@ -2,6 +2,7 @@ package unused
import
(
.
"github.com/onsi/gomega"
"github.com/phodal/coca/cocatest"
"path/filepath"
"testing"
)
...
...
@@ -9,9 +10,13 @@ import (
func
TestRemoveUnusedImportApp_Analysis
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../../_fixtures/refactor/unused"
codePath
=
filepath
.
FromSlash
(
codePath
)
cocatest
.
ResetGitDir
(
codePath
)
deps1
,
_
,
_
:=
cocatest
.
BuildAnalysisDeps
(
codePath
)
g
.
Expect
(
len
(
deps1
[
0
]
.
Imports
))
.
To
(
Equal
(
3
))
app
:=
NewRemoveUnusedImportApp
(
codePath
)
results
:=
app
.
Analysis
()
...
...
@@ -19,4 +24,10 @@ func TestRemoveUnusedImportApp_Analysis(t *testing.T) {
errorLines
:=
BuildErrorLines
(
results
[
0
])
g
.
Expect
(
errorLines
)
.
To
(
Equal
([]
int
{
3
,
4
,
5
}))
app
.
Refactoring
(
results
)
deps
,
_
,
_
:=
cocatest
.
BuildAnalysisDeps
(
codePath
)
g
.
Expect
(
len
(
deps
[
0
]
.
Imports
))
.
To
(
Equal
(
0
))
cocatest
.
ResetGitDir
(
codePath
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录