提交 4d24b117 编写于 作者: 陈琦

close task#36671 文本支持支持重复语法[a,b,c]{5!}

上级 0afdd340
Version = 1.8 Version = 1.8
Language = zh Language = zh
fields: fields:
- field: first - field: first
range: 16_from_instance.yaml{10} range: 16_from_instance.yaml{10} # 注意此处{10}为取10条记录,非重复语法。
prefix: "From 16.yaml\t" prefix: "From 16.yaml\t"
postfix: "\t|\t" postfix: "\t|\t"
- field: second - field: second
range: 17_from_excel.yaml{5} range: 17_from_excel.yaml{5} # 注意此处{5}为取5条记录,非重复语法。
prefix: "From 17.yaml: \t" prefix: "From 17.yaml: \t"
...@@ -104,7 +104,7 @@ fields: ...@@ -104,7 +104,7 @@ fields:
postfix: "\t" postfix: "\t"
- field: field_yaml # 引用其他的定义文件整体内容。 - field: field_yaml # 引用其他的定义文件整体内容。
range: 01_range.yaml{3} # 相对当前文件路径。 range: 01_range.yaml{3} # 相对当前文件路径,注意此处{3}为取5条记录,非重复语法
postfix: "\t" postfix: "\t"
- field: field_use_config # 引用其他的config定义文件。 - field: field_use_config # 引用其他的config定义文件。
......
...@@ -83,41 +83,29 @@ func ParseDesc(desc string) (items []string) { ...@@ -83,41 +83,29 @@ func ParseDesc(desc string) (items []string) {
step =>1 step =>1
repeat =>2 repeat =>2
*/ */
func ParseRangeSection(item string) (entry string, step string, repeat int, repeatTag string) { func ParseRangeSection(rang string) (entry string, step string, repeat int, repeatTag string) {
item = strings.TrimSpace(item) rang = strings.TrimSpace(rang)
if item == "" { if rang == "" {
repeat = 1 repeat = 1
return return
} }
runeArr := []rune(item) runeArr := []rune(rang)
if (runeArr[0] == constant.Backtick && runeArr[len(runeArr)-1] == constant.Backtick) || // `xxx` if (runeArr[0] == constant.Backtick && runeArr[len(runeArr)-1] == constant.Backtick) || // `xxx`
(string(runeArr[0]) == string(constant.LeftBrackets) && // (xxx) (string(runeArr[0]) == string(constant.LeftBrackets) && // (xxx)
string(runeArr[len(runeArr)-1]) == string(constant.RightBrackets)) { string(runeArr[len(runeArr)-1]) == string(constant.RightBrackets)) {
entry = item entry = rang
if repeat == 0 { if repeat == 0 {
repeat = 1 repeat = 1
} }
return return
} }
regx := regexp.MustCompile(`\{(.*)!?\}`) repeat, repeatTag, rangWithoutRepeat := ParseRepeat(rang)
arr := regx.FindStringSubmatch(item)
tag := ""
if len(arr) == 2 {
str := strings.TrimSpace(arr[1])
if str[len(str)-1:] == "!" {
tag = str[len(str)-1:]
str = strings.TrimSpace(str[:len(str)-1])
}
repeat, _ = strconv.Atoi(str)
}
repeatTag = tag
itemWithoutRepeat := regx.ReplaceAllString(item, "")
sectionArr := strings.Split(itemWithoutRepeat, ":") sectionArr := strings.Split(rangWithoutRepeat, ":")
entry = sectionArr[0] entry = sectionArr[0]
if len(sectionArr) == 2 { if len(sectionArr) == 2 {
step = strings.TrimSpace(strings.ToLower(sectionArr[1])) step = strings.TrimSpace(strings.ToLower(sectionArr[1]))
...@@ -127,7 +115,7 @@ func ParseRangeSection(item string) (entry string, step string, repeat int, repe ...@@ -127,7 +115,7 @@ func ParseRangeSection(item string) (entry string, step string, repeat int, repe
pattern := "\\d+" pattern := "\\d+"
isNum, _ := regexp.MatchString(pattern, step) isNum, _ := regexp.MatchString(pattern, step)
if !isNum && step != "r" { if !isNum && step != "r" {
entry = item entry = rang
step = "" step = ""
} }
} }
...@@ -255,3 +243,23 @@ func isCharOrNumberScope(str string) bool { ...@@ -255,3 +243,23 @@ func isCharOrNumberScope(str string) bool {
return false return false
} }
func ParseRepeat(rang string) (repeat int, repeatTag, rangeWithoutRepeat string) {
repeat = 1
regx := regexp.MustCompile(`\{(.*)!?\}`)
arr := regx.FindStringSubmatch(rang)
tag := ""
if len(arr) == 2 {
str := strings.TrimSpace(arr[1])
if str[len(str)-1:] == "!" {
tag = str[len(str)-1:]
str = strings.TrimSpace(str[:len(str)-1])
}
repeat, _ = strconv.Atoi(str)
}
repeatTag = tag
rangeWithoutRepeat = regx.ReplaceAllString(rang, "")
return
}
...@@ -18,8 +18,10 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit ...@@ -18,8 +18,10 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit
ranges := strings.Split(strings.TrimSpace(field.Range), ",") ranges := strings.Split(strings.TrimSpace(field.Range), ",")
for _, rang := range ranges { for _, rang := range ranges {
rang = strings.TrimSpace(rang) rang = strings.TrimSpace(rang)
repeat, repeatTag, rangWithoutRepeat := ParseRepeat(rang)
// get file and step string // get file and step string
sectionArr := strings.Split(rang, ":") sectionArr := strings.Split(rangWithoutRepeat, ":")
file := sectionArr[0] file := sectionArr[0]
stepStr := "1" stepStr := "1"
if len(sectionArr) == 2 { if len(sectionArr) == 2 {
...@@ -59,20 +61,50 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit ...@@ -59,20 +61,50 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit
// get index for data retrieve // get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list)-1), step, rand, 1, "") numbs := GenerateIntItems(0, (int64)(len(list)-1), step, rand, 1, "")
// get data by index // gen data by index
index := 0 count := 0
for _, numb := range numbs { if repeatTag == "" {
item := list[numb.(int64)] for _, numb := range numbs {
item := list[numb.(int64)]
if strings.TrimSpace(item) == "" { // ignore empty line
continue
}
if index >= constant.MaxNumb { for i := 0; i < repeat; i++ {
break fieldValue.Values = append(fieldValue.Values, item)
}
if strings.TrimSpace(item) == "" { count++
continue if count >= constant.MaxNumb {
break
}
}
count++
if count >= constant.MaxNumb {
break
}
} }
} else if repeatTag == "!" {
for i := 0; i < repeat; i++ {
for _, numb := range numbs {
item := list[numb.(int64)]
if strings.TrimSpace(item) == "" { // ignore empty line
continue
}
fieldValue.Values = append(fieldValue.Values, item)
count++
if count >= constant.MaxNumb {
break
}
}
fieldValue.Values = append(fieldValue.Values, item) count++
index = index + 1 if count >= constant.MaxNumb {
break
}
}
} }
} }
......
title: test
desc: 描述
version: 1.0
fields:
- field: refer_text
range: res/num.txt:2, ../demo/user.txt:R
postfix: "\t"
- field: refer_content
range: ../demo/15_from_range.yaml{3}, ../demo/16_from_instance.yaml{10}
prefix: ""
postfix: "\t"
- field: refer_ranges
from: zentao.number.v1.yaml
use: small{3},netmask
postfix: "\t"
- field: refer_instance
from: ip.v1.yaml
use: privateA{3},privateB{5}
postfix: "\t"
\ No newline at end of file
...@@ -2,21 +2,11 @@ title: test ...@@ -2,21 +2,11 @@ title: test
desc: 描述 desc: 描述
version: 1.0 version: 1.0
fields: fields:
- field: refer_text # - field: refer_text
range: res/num.txt, ../demo/user.txt:R # range: res/num.txt{2!}, ../demo/user.txt:R
postfix: "\t" # postfix: "\t"
- field: refer_content - field: refer_content
range: ../demo/15_from_range.yaml{3}, ../demo/16_from_instance.yaml{10} range: ../demo/15_from_range.yaml{3}, ../demo/16_from_instance.yaml{10}
prefix: "" prefix: ""
postfix: "\t"
- field: refer_ranges
from: zentao.number.v1.yaml
use: small{3},netmask
postfix: "\t"
- field: refer_instance
from: ip.v1.yaml
use: privateA{3},privateB{5}
postfix: "\t" postfix: "\t"
\ No newline at end of file
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
<a-select-option value="config">{{$t('msg.config')}}</a-select-option> <a-select-option value="config">{{$t('msg.config')}}</a-select-option>
<a-select-option value="ranges">{{$t('msg.ranges')}}</a-select-option> <a-select-option value="ranges">{{$t('msg.ranges')}}</a-select-option>
<a-select-option value="instances">{{$t('msg.instances')}}</a-select-option> <a-select-option value="instances">{{$t('msg.instances')}}</a-select-option>
<a-select-option value="yaml">{{$t('msg.exec')}}</a-select-option>
<a-select-option value="excel">{{$t('msg.excel')}}</a-select-option> <a-select-option value="excel">{{$t('msg.excel')}}</a-select-option>
<a-select-option value="text">{{$t('msg.text')}}</a-select-option> <a-select-option value="text">{{$t('msg.text')}}</a-select-option>
<a-select-option value="yaml">{{$t('msg.exec')}}</a-select-option>
<a-select-option value="value">{{$t('form.expr')}}</a-select-option> <a-select-option value="value">{{$t('form.expr')}}</a-select-option>
</a-select> </a-select>
</a-form-model-item> </a-form-model-item>
...@@ -181,6 +181,9 @@ export default { ...@@ -181,6 +181,9 @@ export default {
onReferTypeChanged() { onReferTypeChanged() {
console.log('onReferTypeChanged') console.log('onReferTypeChanged')
if (this.refer.type === 'text') {
this.refer.step = 1
}
this.listReferFileForSelection(this.refer.type, false) this.listReferFileForSelection(this.refer.type, false)
}, },
onReferFileChanged() { onReferFileChanged() {
......
...@@ -51,8 +51,8 @@ const locale = { ...@@ -51,8 +51,8 @@ const locale = {
'msg.instances': 'Instances', 'msg.instances': 'Instances',
'msg.excel': 'Excel', 'msg.excel': 'Excel',
'msg.excel.sheet': 'Excel Sheet', 'msg.excel.sheet': 'Excel Sheet',
'msg.text': 'Text', 'msg.text': 'Text Content',
'msg.exec': 'Execution', 'msg.exec': 'Yaml Result',
'msg.file': 'File', 'msg.file': 'File',
'msg.design.title': 'TestData Design', 'msg.design.title': 'TestData Design',
......
...@@ -46,13 +46,13 @@ const locale = { ...@@ -46,13 +46,13 @@ const locale = {
'msg.no': '', 'msg.no': '',
'msg.data': '数据', 'msg.data': '数据',
'msg.config': '字段', 'msg.config': '配置',
'msg.ranges': '序列', 'msg.ranges': '序列',
'msg.instances': '实例', 'msg.instances': '实例',
'msg.excel': 'Excel', 'msg.excel': 'Excel',
'msg.excel.sheet': 'Excel表格', 'msg.excel.sheet': 'Excel表格',
'msg.text': '文本', 'msg.text': '文本内容',
'msg.exec': '执行', 'msg.exec': 'Yaml结果',
'msg.file': '文件', 'msg.file': '文件',
'msg.design.title': '测试数据设计', 'msg.design.title': '测试数据设计',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册