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

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

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