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

close tasks#7684

上级 c4a629d5
...@@ -8,6 +8,8 @@ fields: ...@@ -8,6 +8,8 @@ fields:
- field: field_step_negative # 区间可以指定步长。 - field: field_step_negative # 区间可以指定步长。
range: z-a:-2 # 9,7,5,4... range: z-a:-2 # 9,7,5,4...
loop: 1-3
loopfix: "|"
prefix: "[" prefix: "["
postfix: "]\t" postfix: "]\t"
...@@ -41,9 +43,9 @@ fields: ...@@ -41,9 +43,9 @@ fields:
use: large{3} use: large{3}
- field: field_use_yaml - field: field_use_yaml
range: test/misc.yaml{2},1-9:R{3} range: 9-7,test/nested1.yaml{5}
prefix: "===" prefix: "***"
postfix: "====\t" postfix: "***\t"
- field: field_literal - field: field_literal
range: "`0000-00`,`AA[2,a-z]`,[1-3]:2{3},`[1-3]:2{3}`" range: "`0000-00`,`AA[2,a-z]`,[1-3]:2{3},`[1-3]:2{3}`"
......
...@@ -5,25 +5,31 @@ version: 1.0 ...@@ -5,25 +5,31 @@ version: 1.0
fields: fields:
- field: test0 - field: test0
range: "''" range: 1-9
loop: 2-3 loop: 2-3
loopfix: "|" loopfix: "|"
# width: 10 # width: 10
- field: test1 - field: test1
range: 9-5:R{2} range: 9-5:R{2}
prefix: "[" prefix: ""
postfix: "]\t" postfix: "\t"
# width: 5 # width: 5
- field: test2 - field: test2
range: [user-2,user3,user4,user5,user6]:R range: [user-2,user3,user4,user5,user6]:R
loop: 2-3 loop: 2-3
loopfix: "|" loopfix: "|"
prefix: "[" prefix: ""
postfix: "]\t" postfix: "\t"
# width: 25 # width: 25
- field: test3
range: test/test.yaml{2},a-z:R{3}
prefix: "---"
postfix: "---\t"
# width: 25
- field: field_with_children - field: field_with_children
fields: fields:
- field: child1 - field: child1
......
title: 测试文件
desc:
author: zentao
version: 1.0
fields:
- field: test0
range: 1-9
postfix: ";\t"
- field: test1
range: a-c,nested2.yaml{2}
prefix: "==="
postfix: "===\t"
\ No newline at end of file
title: 测试文件
desc:
author: zentao
version: 1.0
fields:
- field: test0
range: 1-9
loop: 2-3
loopfix: "|"
postfix: ",\t"
\ No newline at end of file
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/easysoft/zendata/src/model" "github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
fileUtils "github.com/easysoft/zendata/src/utils/file" fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118" i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log" logUtils "github.com/easysoft/zendata/src/utils/log"
...@@ -40,6 +41,10 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str ...@@ -40,6 +41,10 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
field.From = vari.Def.From field.From = vari.Def.From
} }
values := GenerateForField(&field, true) values := GenerateForField(&field, true)
if field.Rand {
rows = randomValues(rows)
}
vari.Def.Fields[index].Precision = field.Precision vari.Def.Fields[index].Precision = field.Precision
topFieldNameToValuesMap[field.Field] = values topFieldNameToValuesMap[field.Field] = values
...@@ -178,7 +183,7 @@ func GenerateFieldValuesForDef(field *model.DefField) []string { ...@@ -178,7 +183,7 @@ func GenerateFieldValuesForDef(field *model.DefField) []string {
values = append(values, val) values = append(values, val)
count++ count++
isRandomAndLoopEnd := (*field).IsRand && (*field).LoopIndex == (*field).LoopEnd isRandomAndLoopEnd := !(*field).IsReferYaml && (*field).IsRand && (*field).LoopIndex == (*field).LoopEnd
// isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values) // isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values)
if count >= vari.Total || isRandomAndLoopEnd { if count >= vari.Total || isRandomAndLoopEnd {
break break
...@@ -354,6 +359,16 @@ func putChildrenToArr(arrOfArr [][]string) (values [][]string) { ...@@ -354,6 +359,16 @@ func putChildrenToArr(arrOfArr [][]string) (values [][]string) {
return return
} }
func randomValues(values [][]string) (ret [][]string) {
length := len(values)
for i := 0; i < length; i++ {
val := commonUtils.RandNum(length)
ret = append(ret, values[val])
}
return
}
func combineChildrenValues(arrOfArr [][]string, total int) (ret []string) { func combineChildrenValues(arrOfArr [][]string, total int) (ret []string) {
valueArr := putChildrenToArr(arrOfArr) valueArr := putChildrenToArr(arrOfArr)
......
...@@ -59,7 +59,8 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit ...@@ -59,7 +59,8 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
} else if typ == "interval" { } else if typ == "interval" {
items = CreateValuesFromInterval(field, desc, stepStr, repeat) items = CreateValuesFromInterval(field, desc, stepStr, repeat)
} else if typ == "yaml" { } else if typ == "yaml" {
items = CreateValuesFromYaml(field, desc, repeat) items = CreateValuesFromYaml(field, desc, stepStr, repeat)
field.IsReferYaml = true
} }
fieldValue.Values = append(fieldValue.Values, items...) fieldValue.Values = append(fieldValue.Values, items...)
...@@ -177,7 +178,7 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string, ...@@ -177,7 +178,7 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
return return
} }
func CreateValuesFromInterval(field *model.DefField, desc string, stepStr string, repeat int) (items []interface{}) { func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repeat int) (items []interface{}) {
elemArr := strings.Split(desc, "-") elemArr := strings.Split(desc, "-")
startStr := elemArr[0] startStr := elemArr[0]
endStr := startStr endStr := startStr
...@@ -220,7 +221,7 @@ func CreateValuesFromInterval(field *model.DefField, desc string, stepStr string ...@@ -220,7 +221,7 @@ func CreateValuesFromInterval(field *model.DefField, desc string, stepStr string
return return
} }
func CreateValuesFromYaml(field *model.DefField, yamlFile string, repeat int) (items []interface{}) { func CreateValuesFromYaml(field *model.DefField, yamlFile, stepStr string, repeat int) (items []interface{}) {
// keep root def, since vari.Def will be overwrite by refer yaml file // keep root def, since vari.Def will be overwrite by refer yaml file
rootDef := vari.Def rootDef := vari.Def
...@@ -229,6 +230,13 @@ func CreateValuesFromYaml(field *model.DefField, yamlFile string, repeat int) (i ...@@ -229,6 +230,13 @@ func CreateValuesFromYaml(field *model.DefField, yamlFile string, repeat int) (i
rows, colIsNumArr, _ := GenerateForDefinition("", configFile, &fieldsToExport) rows, colIsNumArr, _ := GenerateForDefinition("", configFile, &fieldsToExport)
items = Print(rows, constant.FormatData, "", colIsNumArr, fieldsToExport) items = Print(rows, constant.FormatData, "", colIsNumArr, fieldsToExport)
if repeat > 0 {
if repeat > len(items) - 1 {
repeat = len(items) - 1
}
items = items[:repeat]
}
// rollback root def when finish to deal with refer yaml file // rollback root def when finish to deal with refer yaml file
vari.Def = rootDef vari.Def = rootDef
......
...@@ -75,11 +75,13 @@ type FieldSimple struct { ...@@ -75,11 +75,13 @@ type FieldSimple struct {
Loop string `yaml:"loop"` Loop string `yaml:"loop"`
Loopfix string `yaml:"loopfix"` Loopfix string `yaml:"loopfix"`
Format string `yaml:"format"` Format string `yaml:"format"`
Rand bool `yaml:"rand"`
LoopStart int `yaml:"-"` LoopStart int `yaml:"-"`
LoopEnd int `yaml:"-"` LoopEnd int `yaml:"-"`
LoopIndex int `yaml:"-"` LoopIndex int `yaml:"-"`
IsRand bool `yaml:"-"` IsRand bool `yaml:"-"`
IsReferYaml bool `yaml:"-"`
} }
type FieldWithValues struct { type FieldWithValues struct {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册