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

close task#7689

上级 b9c372c7
......@@ -31,7 +31,7 @@ fields:
- field: field_nested_range
from: custom.test.number.v1.yaml
use: medium
use: all{3}
prefix: "["
postfix: "]"
......
......@@ -10,6 +10,7 @@ import (
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"regexp"
"strconv"
"strings"
)
......@@ -86,12 +87,29 @@ func GenerateForField(field *model.DefField, total int, withFix bool) (values []
groupValues := vari.Res[field.From]
groups := strings.Split(field.Use, ",")
for _, group := range groups {
regx := regexp.MustCompile(`\{(.*)\}`)
arr := regx.FindStringSubmatch(group)
group = regx.ReplaceAllString(group, "")
num := 0
if len(arr) == 2 {
num, _ = strconv.Atoi(arr[1])
}
i := num
if group == "all" {
for _, arr := range groupValues { // add all
values = append(values, arr...)
valuesFromGroup := arr[:num]
values = append(values, valuesFromGroup...)
i = i - len(valuesFromGroup)
if i <= 0 { break }
}
} else {
values = append(values, groupValues[group]...)
valuesFromGroup := groupValues[group][:num]
values = append(values, valuesFromGroup...)
i = i - len(valuesFromGroup)
if i <= 0 { break }
}
}
} else if field.Select != "" { // refer to excel
......
......@@ -115,14 +115,11 @@ func getResForExcel(resFile string, field *model.DefField) (map[string][]string,
return valueMap, resName
}
func getResForYaml(resFile string) (map[string][]string, string) {
resName := ""
valueMap := map[string][]string{}
func getResForYaml(resFile string) (valueMap map[string][]string, resName string) {
yamlContent, err := ioutil.ReadFile(resFile)
if err != nil {
logUtils.PrintTo(i118Utils.I118Prt.Sprintf("fail_to_read_file", resFile))
return valueMap, ""
return
}
insts := model.ResInsts{}
......@@ -146,7 +143,7 @@ func getResForYaml(resFile string) (map[string][]string, string) {
}
}
return valueMap, resName
return
}
func getResForInstances(insts model.ResInsts) map[string][]string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册