提交 2859799d 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

sort scripts languages options

上级 e23428c0
......@@ -23,7 +23,7 @@ func Generate(productId string, moduleId string, suiteId string, taskId string,
&independentFile, &scriptLang)
}
ok := langUtils.CheckSupportLangages(scriptLang)
ok := langUtils.CheckSupportLanguages(scriptLang)
if !ok {
return
}
......
......@@ -21,7 +21,7 @@ func GetAllScriptsInDir(filePthParam string, files *[]string) error {
sep := string(os.PathSeparator)
if !fileUtils.IsDir(filePthParam) { // first call, param is file
regx := langUtils.GetSupportLangageRegx()
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", filePthParam)
......@@ -50,7 +50,7 @@ func GetAllScriptsInDir(filePthParam string, files *[]string) error {
GetAllScriptsInDir(filePthParam+name+sep, files)
} else {
path := filePthParam + name
regx := langUtils.GetSupportLangageRegx()
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", path)
if pass {
......@@ -84,7 +84,7 @@ func GetScriptByIdsInDir(dirPth string, idMap map[int]string, files *[]string) e
if fi.IsDir() { // 目录, 递归遍历
GetScriptByIdsInDir(dirPth+name+sep, idMap, files)
} else {
regx := langUtils.GetSupportLangageRegx()
regx := langUtils.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", name)
if !pass {
......
......@@ -99,7 +99,6 @@ func GenerateTestCaseScript(cs model.TestCase, langType string, independentFile
func GenerateTestStepScript(ts model.TestStep, langType string, stepWidth int,
steps *[]string, expects *[]string, srcCode *[]string) {
LangMap := langUtils.GetSupportedScriptLang()
isGroup := ts.Type == "group"
isCheckPoint := ts.Expect != ""
......@@ -147,11 +146,11 @@ func GenerateTestStepScript(ts model.TestStep, langType string, stepWidth int,
// 处理srcCode
if isCheckPoint {
codeLine := LangMap[langType]["printGrammar"]
codeLine := langUtils.LangMap[langType]["printGrammar"]
codeLine += fmt.Sprintf(" %s %s: %s\n", LangMap[langType]["commentsTag"], stepIdent, stepExpect)
codeLine += fmt.Sprintf(" %s %s: %s\n", langUtils.LangMap[langType]["commentsTag"], stepIdent, stepExpect)
codeLine += LangMap[langType]["commentsTag"] + "CODE: " + i118Utils.I118Prt.Sprintf("actual_result_here")
codeLine += langUtils.LangMap[langType]["commentsTag"] + "CODE: " + i118Utils.I118Prt.Sprintf("actual_result_here")
*srcCode = append(*srcCode, codeLine)
}
......
......@@ -5,6 +5,7 @@ import (
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stringUtils "github.com/easysoft/zentaoatf/src/utils/string"
"github.com/fatih/color"
"sort"
"strconv"
"strings"
"sync"
......@@ -12,7 +13,7 @@ import (
var LangMap map[string]map[string]string
func GetSupportedScriptLang() map[string]map[string]string {
func initSupportedScriptLang() map[string]map[string]string {
var once sync.Once
once.Do(func() {
LangMap = map[string]map[string]string{
......@@ -68,7 +69,7 @@ func GetSupportedScriptLang() map[string]map[string]string {
}
func GetSupportLanguageOptions() ([]string, []string, []string) {
arr0 := GetSupportLangageArr()
arr0 := GetSupportLanguageArrSort()
numbs := make([]string, 0)
names := make([]string, 0)
......@@ -90,46 +91,42 @@ func GetSupportLanguageOptions() ([]string, []string, []string) {
return numbs, names, labels
}
func GetSupportLangageArr() []string {
langMap := GetSupportedScriptLang()
func GetSupportLanguageArrSort() []string {
arr := make([]string, 0)
for lang, _ := range langMap {
for lang, _ := range LangMap {
arr = append(arr, lang)
}
sort.Strings(arr)
return arr
}
func GetSupportLangageExtArr() []string {
langMap := GetSupportedScriptLang()
func GetSupportLanguageExtArr() []string {
arr := make([]string, 0)
for _, val := range langMap {
arr = append(arr, val["extName"])
for _, key := range GetSupportLanguageArrSort() {
arr = append(arr, LangMap[key]["extName"])
}
return arr
}
func CheckSupportLangages(scriptLang string) bool {
langMap := GetSupportedScriptLang()
if langMap[scriptLang] == nil {
langs := strings.Join(GetSupportLangageArr(), ", ")
logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("only_support_script_language", langs)+"\n", color.FgRed)
func CheckSupportLanguages(scriptLang string) bool {
if LangMap[scriptLang] == nil {
langStr := strings.Join(GetSupportLanguageArrSort(), ", ")
logUtils.PrintToCmd(i118Utils.I118Prt.Sprintf("only_support_script_language", langStr)+"\n", color.FgRed)
return false
}
return true
}
func GetSupportLangageRegx() string {
regx := "(" + strings.Join(GetSupportLangageExtArr(), "|") + ")"
func GetSupportLanguageExtRegx() string {
regx := "(" + strings.Join(GetSupportLanguageExtArr(), "|") + ")"
return regx
}
func init() {
GetSupportedScriptLang()
initSupportedScriptLang()
}
......@@ -63,7 +63,8 @@ func InputForCheckout(productId *string, moduleId *string, suiteId *string, task
numbs, names, labels := langUtils.GetSupportLanguageOptions()
fmtParam := strings.Join(labels, "\n")
langStr := GetInput("("+strings.Join(numbs, "|")+")", "enter_co_language", fmtParam)
langStr := GetInput("("+strings.Join(numbs, "|")+")", "", "enter_co_language", fmtParam)
langNumb, _ := strconv.Atoi(langStr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册