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

cloes task#7499

上级 1154736b
......@@ -29,20 +29,23 @@ fields:
- field: test6
fields:
- field: child1
range: X-Z
range: 1.0-9.9:R
loop: 2
loopfix: "|"
prefix: ""
postfix: "\t"
- field: child2
fields:
- field: child2.1
range: a-b
prefix:
range: a-c:R
loop: 2
loopfix: ","
prefix: ""
postfix: "\t"
- field: child2.2
range: 1-9:R
loop: 3
loopfix: ","
prefix: "["
postfix: "]"
prefix: ""
......@@ -18,6 +18,5 @@ require (
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
gopkg.in/ini.v1 v1.55.0
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20200602174320-3e3e88ca92fa
)
......@@ -179,12 +179,11 @@ func replacePlaceholder(col string) string {
strForReplaceMap := map[string][]string{}
for _, childArr := range arr {
placeholderStr := childArr[1]
//if strForReplaceMap[placeholderStr] == nil {
strForReplaceMap[placeholderStr] = getValForPlaceholder(placeholderStr, len(childArr))
//}
strForReplaceMap[placeholderStr] = getValForPlaceholder(placeholderStr, len(childArr))
for _, str := range strForReplaceMap[placeholderStr] {
ret = strings.Replace(ret, gen.Placeholder(placeholderStr), str, 1)
temp := gen.Placeholder(placeholderStr)
ret = strings.Replace(ret, temp, str, 1)
}
}
......@@ -220,7 +219,7 @@ func getValForPlaceholder(placeholderStr string, count int) []string {
strs = gen.GetRandFromRange("char", start, end, "1", repeat, precision, count)
} else if tp == "list" {
list := mp["list"].([]interface{})
list := mp["list"].([]string)
strs = gen.GetRandFromList(list, repeat, count)
}
......@@ -237,7 +236,10 @@ func printLine(line string) {
}
}
func PrintToFile(line string) {
fmt.Fprintln(FileWriter, line)
fmt.Fprintln(FileWriter, "==========")
fmt.Fprintln(FileWriter, "1.0|8.0\tb,a\t3,1,1")
fmt.Fprintln(FileWriter, "----------")
fmt.Fprintln(FileWriter, "a\tb\tc")
}
func PrintToHttp(line string) {
fmt.Fprintln(HttpWriter, line)
......
......@@ -184,7 +184,7 @@ func GenerateValuesFromInterval(field *model.DefField, desc string, stepStr stri
if dataType != "string" && rand {
items = append(items, Placeholder(field.Path))
mp := placeholderMapForRandValues(dataType, []string{}, startStr, endStr, stepStr, "")
mp := placeholderMapForRandValues(dataType, []string{}, startStr, endStr, stepStr, strconv.Itoa(precision))
vari.RandFieldNameToValuesMap[field.Path] = mp
return
......@@ -201,7 +201,7 @@ func GenerateValuesFromInterval(field *model.DefField, desc string, stepStr stri
endFloat, _ := strconv.ParseFloat(endStr, 64)
field.Precision = precision
items = GenerateFloatItemsByStep(startFloat, endFloat, step.(int), repeat)
items = GenerateFloatItemsByStep(startFloat, endFloat, step.(float64), repeat)
} else if dataType == "char" {
items = GenerateByteItemsByStep(startStr[0], endStr[0], step.(int), repeat)
......
......@@ -6,7 +6,7 @@ import (
"strings"
)
func GetRandFromList(list []interface{}, repeatStr string, count int) []string {
func GetRandFromList(list []string, repeatStr string, count int) []string {
ret := make([]string, 0)
for i := 0; i < count; i++ {
......@@ -16,7 +16,7 @@ func GetRandFromList(list []interface{}, repeatStr string, count int) []string {
repeat, _ := strconv.Atoi(repeatStr)
items := make([]string, 0)
for round := 0; round < repeat; round++ {
items = append(items, val.(string))
items = append(items, val)
}
ret = append(ret, strings.Join(items, ""))
......@@ -79,7 +79,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
endFloat, _ := strconv.ParseFloat(end, 64)
stepFloat, _ := strconv.ParseFloat(step, 64)
countInRound := (startFloat - endFloat) / stepFloat
countInRound := (endFloat - startFloat) / stepFloat
for i := 0; i < count; i++ {
rand := commonUtils.RandNum64(int64(countInRound))
......
......@@ -173,7 +173,7 @@ func toGen() {
if output != "" {
fileUtils.RemoveExist(output)
action.FileWriter, _ = os.OpenFile(output, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
action.FileWriter, _ = os.OpenFile(output, os.O_RDWR | os.O_CREATE, 0777)
defer action.FileWriter.Close()
ext := strings.ToLower(path.Ext(output))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册