Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
cc7d585b
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
10 个月 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cc7d585b
编写于
5月 18, 2023
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix sonar issues
上级
6e2c910c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
147 addition
and
117 deletion
+147
-117
internal/pkg/helper/exec/result.go
internal/pkg/helper/exec/result.go
+147
-117
未找到文件。
internal/pkg/helper/exec/result.go
浏览文件 @
cc7d585b
...
...
@@ -181,7 +181,7 @@ func ValidateStepResult(langType string, expectLines []string, actualLines []str
pass
=
MatchScene
(
expect
[
1
:
len
(
expect
)
-
1
],
log
,
langType
)
}
else
if
len
(
expect
)
>=
2
&&
expect
[
:
1
]
==
"`"
&&
expect
[
len
(
expect
)
-
1
:
]
==
"`"
{
expect
=
expect
[
1
:
len
(
expect
)
-
1
]
pass
=
Match
String
(
expect
,
log
,
langType
)
pass
=
Match
(
expect
,
log
)
}
else
{
pass
=
strings
.
TrimSpace
(
log
)
==
strings
.
TrimSpace
(
expect
)
}
...
...
@@ -200,7 +200,54 @@ func ValidateStepResult(langType string, expectLines []string, actualLines []str
}
func
MatchString
(
expect
string
,
actual
string
,
langType
string
)
bool
{
func
MatchScene
(
expect
,
actual
,
langType
string
)
(
pass
bool
)
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
if
len
(
expect
)
==
0
{
pass
=
actual
==
""
return
}
if
len
(
expect
)
<=
2
{
return
}
// len(expect) > 2
scene
:=
expect
[
:
2
]
expect
=
strings
.
TrimSpace
(
expect
[
2
:
])
switch
scene
{
case
"f:"
:
return
Contain
(
expect
,
actual
,
langType
)
case
"m:"
:
return
Match
(
expect
,
actual
)
case
"c:"
:
return
Compare
(
expect
,
actual
)
case
"l:"
:
return
Logic
(
expect
,
actual
,
langType
)
}
return
}
func
Contain
(
expect
,
actual
string
,
langType
string
)
bool
{
if
strings
.
Contains
(
expect
,
"*"
)
{
expectArr
:=
strings
.
Split
(
expect
,
"*"
)
repeatCount
,
_
:=
strconv
.
Atoi
(
string
(
expectArr
[
1
]))
return
strings
.
Count
(
actual
,
expectArr
[
0
])
>=
repeatCount
}
if
expect
[
0
:
1
]
==
"("
&&
expect
[
len
(
expect
)
-
1
:
]
==
")"
&&
strings
.
Contains
(
expect
,
","
)
{
expect
=
fmt
.
Sprintf
(
"^%s{1}$"
,
strings
.
ReplaceAll
(
expect
,
","
,
"|"
))
}
return
Match
(
expect
,
actual
)
}
func
Match
(
expect
string
,
actual
string
)
bool
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
...
...
@@ -215,124 +262,107 @@ func MatchString(expect string, actual string, langType string) bool {
return
pass
}
func
MatchScene
(
expect
,
actual
,
langType
string
)
(
pass
bool
)
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
if
len
(
expect
)
==
0
{
return
actual
==
""
func
Compare
(
expect
string
,
actual
string
)
bool
{
if
len
(
expect
)
>
2
&&
(
expect
[
:
2
]
==
">="
||
expect
[
:
2
]
==
"<="
||
expect
[
:
2
]
==
"<>"
||
expect
[
:
2
]
==
"!="
)
{
character
:=
expect
[
:
2
]
expectFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expect
[
2
:
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
switch
character
{
case
">="
:
return
actualFloot
>=
expectFloot
case
"<="
:
return
actualFloot
<=
expectFloot
case
"<>"
:
return
actualFloot
!=
expectFloot
case
"!="
:
return
actualFloot
!=
expectFloot
}
return
false
}
if
len
(
expect
)
>
2
{
scene
:=
expect
[
:
2
]
expect
=
strings
.
TrimSpace
(
expect
[
2
:
])
switch
scene
{
case
"f:"
:
if
strings
.
Contains
(
expect
,
"*"
)
{
expectArr
:=
strings
.
Split
(
expect
,
"*"
)
repeatCount
,
_
:=
strconv
.
Atoi
(
string
(
expectArr
[
1
]))
return
strings
.
Count
(
actual
,
expectArr
[
0
])
>=
repeatCount
}
if
expect
[
0
:
1
]
==
"("
&&
expect
[
len
(
expect
)
-
1
:
]
==
")"
&&
strings
.
Contains
(
expect
,
","
)
{
expect
=
fmt
.
Sprintf
(
"^%s{1}$"
,
strings
.
ReplaceAll
(
expect
,
","
,
"|"
))
}
return
MatchString
(
expect
,
actual
,
langType
)
case
"m:"
:
return
MatchString
(
expect
,
actual
,
langType
)
case
"c:"
:
if
len
(
expect
)
>
2
&&
(
expect
[
:
2
]
==
">="
||
expect
[
:
2
]
==
"<="
||
expect
[
:
2
]
==
"<>"
||
expect
[
:
2
]
==
"!="
)
{
character
:=
expect
[
:
2
]
expectFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expect
[
2
:
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
switch
character
{
case
">="
:
return
actualFloot
>=
expectFloot
case
"<="
:
return
actualFloot
<=
expectFloot
case
"<>"
:
return
actualFloot
!=
expectFloot
case
"!="
:
return
actualFloot
!=
expectFloot
}
}
else
if
strings
.
Contains
(
expect
,
"-"
)
&&
strings
.
Count
(
expect
,
"-"
)
==
1
{
rangeArr
:=
strings
.
Split
(
expect
,
"-"
)
rangeFrom
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
rangeArr
[
0
]),
64
)
if
err
!=
nil
{
return
false
}
rangeTo
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
rangeArr
[
1
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
return
actualFloot
>=
rangeFrom
&&
actualFloot
<=
rangeTo
}
else
{
character
:=
expect
[
:
1
]
expectFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expect
[
1
:
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
switch
character
{
case
">"
:
return
actualFloot
>
expectFloot
case
"<"
:
return
actualFloot
<
expectFloot
case
"="
:
return
actualFloot
==
expectFloot
}
if
strings
.
Contains
(
expect
,
"-"
)
{
expectArr
:=
strings
.
Split
(
expect
,
"-"
)
expectMin
,
_
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expectArr
[
0
]),
64
)
expectMax
,
_
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expectArr
[
1
]),
64
)
return
actualFloot
>=
expectMin
&&
actualFloot
<=
expectMax
}
}
case
"l:"
:
openParenthesisCount
,
closeParenthesisCount
:=
0
,
0
hasLogicCharacter
:=
false
for
index
,
v
:=
range
expect
{
if
v
==
'('
{
openParenthesisCount
++
}
else
if
v
==
')'
{
closeParenthesisCount
++
}
if
v
==
'&'
||
v
==
'|'
{
hasLogicCharacter
=
true
}
if
v
==
'|'
&&
index
>
0
&&
expect
[
index
-
1
]
!=
'\\'
&&
(
openParenthesisCount
==
closeParenthesisCount
)
{
return
MatchScene
(
"l:"
+
expect
[
:
index
],
actual
,
langType
)
||
MatchScene
(
"l:"
+
expect
[
index
+
1
:
],
actual
,
langType
)
}
else
if
v
==
'&'
&&
index
>
0
&&
string
(
expect
[
index
-
1
])
!=
"
\\
"
&&
(
openParenthesisCount
==
closeParenthesisCount
)
{
return
MatchScene
(
"l:"
+
expect
[
:
index
],
actual
,
langType
)
&&
MatchScene
(
"l:"
+
expect
[
index
+
1
:
],
actual
,
langType
)
}
}
if
expect
[
:
1
]
==
"("
{
expect
=
expect
[
1
:
]
}
if
expect
[
len
(
expect
)
-
1
:
]
==
")"
{
expect
=
expect
[
:
len
(
expect
)
-
1
]
}
if
!
hasLogicCharacter
{
if
expect
[
:
1
]
==
"!"
{
return
!
MatchScene
(
expect
[
1
:
],
actual
,
langType
)
}
return
MatchScene
(
expect
,
actual
,
langType
)
}
else
{
return
MatchScene
(
"l:"
+
expect
,
actual
,
langType
)
}
if
strings
.
Contains
(
expect
,
"-"
)
&&
strings
.
Count
(
expect
,
"-"
)
==
1
{
rangeArr
:=
strings
.
Split
(
expect
,
"-"
)
rangeFrom
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
rangeArr
[
0
]),
64
)
if
err
!=
nil
{
return
false
}
rangeTo
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
rangeArr
[
1
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
return
actualFloot
>=
rangeFrom
&&
actualFloot
<=
rangeTo
}
return
pass
character
:=
expect
[
:
1
]
expectFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expect
[
1
:
]),
64
)
if
err
!=
nil
{
return
false
}
actualFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
actual
),
64
)
if
err
!=
nil
{
return
false
}
switch
character
{
case
">"
:
return
actualFloot
>
expectFloot
case
"<"
:
return
actualFloot
<
expectFloot
case
"="
:
return
actualFloot
==
expectFloot
}
if
strings
.
Contains
(
expect
,
"-"
)
{
expectArr
:=
strings
.
Split
(
expect
,
"-"
)
expectMin
,
_
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expectArr
[
0
]),
64
)
expectMax
,
_
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expectArr
[
1
]),
64
)
return
actualFloot
>=
expectMin
&&
actualFloot
<=
expectMax
}
return
false
}
func
Logic
(
expect
,
actual
,
langType
string
)
bool
{
openParenthesisCount
,
closeParenthesisCount
:=
0
,
0
hasLogicCharacter
:=
false
for
index
,
v
:=
range
expect
{
if
v
==
'('
{
openParenthesisCount
++
}
else
if
v
==
')'
{
closeParenthesisCount
++
}
if
v
==
'&'
||
v
==
'|'
{
hasLogicCharacter
=
true
}
if
v
==
'|'
&&
index
>
0
&&
expect
[
index
-
1
]
!=
'\\'
&&
(
openParenthesisCount
==
closeParenthesisCount
)
{
return
MatchScene
(
"l:"
+
expect
[
:
index
],
actual
,
langType
)
||
MatchScene
(
"l:"
+
expect
[
index
+
1
:
],
actual
,
langType
)
}
else
if
v
==
'&'
&&
index
>
0
&&
string
(
expect
[
index
-
1
])
!=
"
\\
"
&&
(
openParenthesisCount
==
closeParenthesisCount
)
{
return
MatchScene
(
"l:"
+
expect
[
:
index
],
actual
,
langType
)
&&
MatchScene
(
"l:"
+
expect
[
index
+
1
:
],
actual
,
langType
)
}
}
if
expect
[
:
1
]
==
"("
{
expect
=
expect
[
1
:
]
}
if
expect
[
len
(
expect
)
-
1
:
]
==
")"
{
expect
=
expect
[
:
len
(
expect
)
-
1
]
}
if
!
hasLogicCharacter
{
if
expect
[
:
1
]
==
"!"
{
return
!
MatchScene
(
expect
[
1
:
],
actual
,
langType
)
}
return
MatchScene
(
expect
,
actual
,
langType
)
}
else
{
return
MatchScene
(
"l:"
+
expect
,
actual
,
langType
)
}
return
false
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录