提交 9022e360 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

fix issue

上级 a52d1848
......@@ -31,7 +31,7 @@ func Extract(scriptPaths []string) error {
steps := prepareSteps(stepObjs)
desc := prepareDesc(steps, pth)
replaceCaseDesc(desc, pth)
ReplaceCaseDesc(desc, pth)
}
return nil
......@@ -177,19 +177,6 @@ func prepareDesc(steps []string, file string) (desc string) {
return
}
func replaceCaseDesc(desc, file string) {
content := fileUtils.ReadFile(file)
lang := langUtils.GetLangByFile(file)
regStr := fmt.Sprintf(`(?smU)%s((?U:.*pid.*))\n(.*)%s`,
langUtils.LangCommentsRegxMap[lang][0], langUtils.LangCommentsRegxMap[lang][1])
re, _ := regexp.Compile(regStr)
out := re.ReplaceAllString(content, "\n/**\n\n"+desc+"\n\n*/")
fileUtils.WriteFile(file, out)
}
func getName(line, str, lang string) (name, expect string) {
lowerLine := strings.ToLower(line)
......@@ -204,9 +191,8 @@ func getName(line, str, lang string) (name, expect string) {
}
}
regx, _ := regexp.Compile(langUtils.LangCommentsTagMap[lang][1])
name = strings.TrimSpace(regx.ReplaceAllString(name, ""))
expect = strings.TrimSpace(regx.ReplaceAllString(expect, ""))
name = strings.TrimSpace(strings.Replace(name, langUtils.LangCommentsTagMap[lang][1], "", -1))
expect = strings.TrimSpace(strings.Replace(expect, langUtils.LangCommentsTagMap[lang][1], "", -1))
return
}
......
......@@ -10,7 +10,6 @@ import (
langUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/lang"
resUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/res"
"path/filepath"
"regexp"
"strconv"
"strings"
)
......@@ -65,19 +64,8 @@ func GenerateScript(cs commDomain.ZtfCase, langType string, independentFile bool
}
if fileUtils.FileExist(scriptFile) { // update title and steps
regStr := fmt.Sprintf(`(?sm)%s((?U:.*pid.*))\n(.*)%s`,
langUtils.LangCommentsRegxMap[langType][0], langUtils.LangCommentsRegxMap[langType][1])
// replace info
re, _ := regexp.Compile(regStr)
newContent := fmt.Sprintf("\n%s\n\n%s\n\n%s\n",
langUtils.LangCommentsTagMap[langType][0],
strings.Join(info, "\n"),
langUtils.LangCommentsTagMap[langType][1])
out := re.ReplaceAllString(content, newContent)
fileUtils.WriteFile(scriptFile, out)
newContent := strings.Join(info, "\n")
ReplaceCaseDesc(newContent, scriptFile)
return
}
......@@ -166,7 +154,7 @@ func generateTestStepAndScriptObsolete(testSteps []commDomain.ZtfStep, steps *[]
GetCaseContent(child, strconv.Itoa(stepNumb), independentFile, group.MultiLine)...)
if independentFile && strings.TrimSpace(child.Expect) != "" {
*independentExpects = append(*independentExpects, getExcepts(child.Expect))
*independentExpects = append(*independentExpects, getExcepts(child.Expect, false))
}
stepNumb++
......@@ -179,7 +167,7 @@ func generateTestStepAndScriptObsolete(testSteps []commDomain.ZtfStep, steps *[]
*steps = append(*steps, GetCaseContent(child, numbStr, independentFile, group.MultiLine)...)
if independentFile && strings.TrimSpace(child.Expect) != "" {
*independentExpects = append(*independentExpects, getExcepts(child.Expect))
*independentExpects = append(*independentExpects, getExcepts(child.Expect, false))
}
}
......@@ -210,14 +198,22 @@ func generateTestStepAndScript(testSteps []commDomain.ZtfStep, steps *[]string,
*steps = append(*steps, "")
for _, item := range nestedSteps {
numbStr := fmt.Sprintf("%d", stepNumb)
*steps = append(*steps, GetCaseContent(item, numbStr, independentFile, false)...)
stepLines1 := GetCaseContent(item, numbStr, independentFile, false)
*steps = append(*steps, stepLines1...)
if independentFile && strings.TrimSpace(item.Expect) != "" {
expects1 := getExcepts(item.Expect, independentFile)
*independentExpects = append(*independentExpects, expects1)
}
for childNo, child := range item.Children {
numbStr := fmt.Sprintf("%d.%d", stepNumb, childNo+1)
*steps = append(*steps, GetCaseContent(child, numbStr, independentFile, true)...)
stepLines2 := GetCaseContent(child, numbStr, independentFile, true)
*steps = append(*steps, stepLines2...)
if independentFile && strings.TrimSpace(child.Expect) != "" {
*independentExpects = append(*independentExpects, getExcepts(child.Expect))
expects2 := getExcepts(child.Expect, independentFile)
*independentExpects = append(*independentExpects, expects2)
}
}
......
......@@ -19,16 +19,38 @@ import (
"strings"
)
func getExcepts(str string) string {
str = stringUtils.TrimAll(str)
func ReplaceCaseDesc(desc, file string) {
content := fileUtils.ReadFile(file)
lang := langUtils.GetLangByFile(file)
regStr := fmt.Sprintf(`(?smU)%s((?U:.*pid.*))\n(.*)%s`,
langUtils.LangCommentsRegxMap[lang][0], langUtils.LangCommentsRegxMap[lang][1])
re, _ := regexp.Compile(regStr)
newDesc := fmt.Sprintf("\n%s\n\n"+desc+"\n\n%s",
langUtils.LangCommentsTagMap[lang][0],
langUtils.LangCommentsTagMap[lang][1])
out := re.ReplaceAllString(content, newDesc)
fileUtils.WriteFile(file, out)
}
func getExcepts(str string, independentFile bool) (ret string) {
str = stringUtils.TrimAll(str)
arr := strings.Split(str, "\n")
if len(arr) == 1 {
return ">> " + str
ret = str
if len(arr) == 1 && !independentFile {
ret = ">> " + str
} else if len(arr) == 1 && independentFile {
ret = str
} else {
return ">>\n" + str
ret = ">>\n" + str
}
return
}
func GetStepAndExpectMap(file string) (stepMap, stepTypeMap, expectMap maps.Map, isOldFormat bool) {
......@@ -599,7 +621,13 @@ func GetCaseContent(stepObj commDomain.ZtfStep, seq string, independentFile bool
stepStr := getStepContent(step, isChild)
expectStr := getExpectContent(expect, isChild, independentFile)
lines = append(lines, stepStr+expectStr)
line := ""
if !independentFile {
line = stepStr + expectStr
} else {
line = stepStr + " >>"
}
lines = append(lines, line)
return lines
}
......@@ -632,12 +660,12 @@ func getExpectContent(str string, isChild bool, independentFile bool) (ret strin
ret = " >> " + str
}
} else {
rpl := "\r\n" + " "
rpl := "\r\n"
if independentFile {
ret = ">>\n" + strings.ReplaceAll(str, "\r\n", rpl) + "\n>>"
ret = ">>\n" + strings.ReplaceAll(str, rpl, rpl+" ") + "\n>>"
} else {
ret = " >> " + strings.ReplaceAll(str, "\r\n", rpl) + "\n>>"
ret = " >> " + strings.ReplaceAll(str, rpl, rpl+" ") + "\n>>"
}
}
......
......@@ -43,28 +43,4 @@ var (
RunModeCommon = "common"
RunModeServer = "server"
RunModeRequest = "request"
LangCommentsTagMap = map[string][]string{
"bat": {"goto start", ":start"},
"javascript": {"/\\*{1,}", "\\*{1,}/"},
"lua": {"--\\[\\[", "\\]\\]"},
"perl": {"=pod", "=cut"},
"php": {"/\\*{1,}", "\\*{1,}/"},
"python": {"'''", "'''"},
"ruby": {"=begin", "=end"},
"shell": {":<<!", "!"},
"tcl": {"set case {", "}"},
}
LangCommentsRegxMap = map[string][]string{
"bat": {"^\\s*goto start\\s*$", "^\\s*:start\\s*$"},
"javascript": {"^\\s*/\\*{1,}\\s*$", "^\\s*\\*{1,}/\\s*$"},
"lua": {"^\\s*--\\[\\[\\s*$", "^\\s*\\]\\]\\s*$"},
"perl": {"^\\s*=pod\\s*$", "^\\s*=cut\\s*$"},
"php": {"^\\s*/\\*{1,}\\s*$", "^\\s*\\*{1,}/\\s*$"},
"python": {"^\\s*'''\\s*$", "^\\s*'''\\s*$"},
"ruby": {"^\\s*=begin\\s*$", "^\\s*=end\\s*$"},
"shell": {"^\\s*:<<!\\s*$", "^\\s*!\\s*$"},
"tcl": {"^\\s*set case {", "^\\s*}"},
}
)
......@@ -2,15 +2,15 @@ package langUtils
var (
LangCommentsTagMap = map[string][]string{
"bat": {"goto start", ":start"},
"javascript": {"/\\*", "\\*/"},
"lua": {"--\\[\\[", "\\]\\]"},
"perl": {"=pod", "=cut"},
"php": {"/\\*", "\\*/"},
"bat": {`goto start`, `:start`},
"javascript": {`/*`, `*/`},
"lua": {`--[[`, `]]`},
"perl": {`=pod`, `=cut`},
"php": {`/**`, `*/`},
"python": {"'''", "'''"},
"ruby": {"=begin", "=end"},
"shell": {":<<!", "!"},
"tcl": {"set case {", "}"},
"ruby": {`=begin`, `=end`},
"shell": {`:<<!`, `!`},
"tcl": {`set case {`, `}`},
}
LangCommentsRegxMap = map[string][]string{
......
......@@ -204,7 +204,7 @@ export default defineComponent({
}
.icon2 {
.svg-icon {
vertical-align: 0.15em !important;
vertical-align: 3px !important;
}
}
.anticon-down {
......
......@@ -87,6 +87,8 @@ export default {
'wrong_url': 'Please input right ZenTao URL.',
'create_project': 'Create Project',
'extract_success': 'Extract comments to test steps and checkpoints successfully.',
'extract_fail': 'Extract comments to test steps and checkpoints failed.',
'pls_create_project': 'Please create project to continue.',
'pls_product': 'Please select product.',
'pls_lang': 'Please select language.',
......
......@@ -88,6 +88,8 @@ export default {
'collapse_all': '收缩全部',
'wrong_url': '请输入正确的的URL地址,以http或https开头。',
'create_project': '新建项目',
'extract_success': '提取注释为测试步骤和验证点成功。',
'extract_fail': '提取注释为测试步骤和验证点失败。',
'pls_create_project': '请点击右上角链接新建项目',
'pls_product': '请选择产品',
'pls_lang': '请选择语言',
......
......@@ -159,13 +159,16 @@ export default defineComponent({
}
const extract = () => {
console.log('extract', selectedNode.props)
scriptCode.value = ''
storeScript.dispatch('script/extractScript', selectedNode.props).then(() => {
scriptCode.value = script.value.code
notification.success({
message: `提取注释为测试步骤和验证点成功!`,
message: t('extract_success'),
})
}).catch(() => {
notification.error({
message: `提取注释为测试步骤和验证点失败!`,
message: t('extract_fail'),
});
})
}
......
......@@ -15,7 +15,7 @@ protoc --go_out=. \
安装打包工具
npm install --save-dev electron-packager
打包
打包客户端
cd ui && yarn build --dest ../client/ui && cd ..
go-bindata -o=res/res.go -pkg=res res/...
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册