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,33 +200,41 @@ func ValidateStepResult(langType string, expectLines []string, actualLines []str
}
func
MatchString
(
expect
string
,
actual
string
,
langType
string
)
bool
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
expect
=
strings
.
Replace
(
expect
,
"%s"
,
`.+?`
,
-
1
)
// 字符串
expect
=
strings
.
Replace
(
expect
,
"%i"
,
`[+\-]?[0-9]+`
,
-
1
)
// 十进制数字,可有符号
expect
=
strings
.
Replace
(
expect
,
"%d"
,
`[0-9]+`
,
-
1
)
// 十进制数字,无符号
expect
=
strings
.
Replace
(
expect
,
"%x"
,
`(0X|0x)?[0-9a-fA-F]+`
,
-
1
)
// 十六进制数字
expect
=
strings
.
Replace
(
expect
,
"%f"
,
`[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?`
,
-
1
)
// 十进制浮点数
expect
=
strings
.
Replace
(
expect
,
"%c"
,
"."
,
-
1
)
// 单个字符
pass
,
_
:=
regexp
.
MatchString
(
expect
,
actual
)
return
pass
}
func
MatchScene
(
expect
,
actual
,
langType
string
)
(
pass
bool
)
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
if
len
(
expect
)
==
0
{
return
actual
==
""
pass
=
actual
==
""
return
}
if
len
(
expect
)
<=
2
{
return
}
if
len
(
expect
)
>
2
{
// 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
]))
...
...
@@ -235,10 +243,26 @@ func MatchScene(expect, actual, langType string) (pass bool) {
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:"
:
return
Match
(
expect
,
actual
)
}
func
Match
(
expect
string
,
actual
string
)
bool
{
expect
=
strings
.
TrimSpace
(
expect
)
actual
=
strings
.
TrimSpace
(
actual
)
expect
=
strings
.
Replace
(
expect
,
"%s"
,
`.+?`
,
-
1
)
// 字符串
expect
=
strings
.
Replace
(
expect
,
"%i"
,
`[+\-]?[0-9]+`
,
-
1
)
// 十进制数字,可有符号
expect
=
strings
.
Replace
(
expect
,
"%d"
,
`[0-9]+`
,
-
1
)
// 十进制数字,无符号
expect
=
strings
.
Replace
(
expect
,
"%x"
,
`(0X|0x)?[0-9a-fA-F]+`
,
-
1
)
// 十六进制数字
expect
=
strings
.
Replace
(
expect
,
"%f"
,
`[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?`
,
-
1
)
// 十进制浮点数
expect
=
strings
.
Replace
(
expect
,
"%c"
,
"."
,
-
1
)
// 单个字符
pass
,
_
:=
regexp
.
MatchString
(
expect
,
actual
)
return
pass
}
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
)
...
...
@@ -259,7 +283,11 @@ func MatchScene(expect, actual, langType string) (pass bool) {
case
"!="
:
return
actualFloot
!=
expectFloot
}
}
else
if
strings
.
Contains
(
expect
,
"-"
)
&&
strings
.
Count
(
expect
,
"-"
)
==
1
{
return
false
}
if
strings
.
Contains
(
expect
,
"-"
)
&&
strings
.
Count
(
expect
,
"-"
)
==
1
{
rangeArr
:=
strings
.
Split
(
expect
,
"-"
)
rangeFrom
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
rangeArr
[
0
]),
64
)
if
err
!=
nil
{
...
...
@@ -274,7 +302,8 @@ func MatchScene(expect, actual, langType string) (pass bool) {
return
false
}
return
actualFloot
>=
rangeFrom
&&
actualFloot
<=
rangeTo
}
else
{
}
character
:=
expect
[
:
1
]
expectFloot
,
err
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expect
[
1
:
]),
64
)
if
err
!=
nil
{
...
...
@@ -298,8 +327,11 @@ func MatchScene(expect, actual, langType string) (pass bool) {
expectMax
,
_
:=
strconv
.
ParseFloat
(
strings
.
TrimSpace
(
expectArr
[
1
]),
64
)
return
actualFloot
>=
expectMin
&&
actualFloot
<=
expectMax
}
}
case
"l:"
:
return
false
}
func
Logic
(
expect
,
actual
,
langType
string
)
bool
{
openParenthesisCount
,
closeParenthesisCount
:=
0
,
0
hasLogicCharacter
:=
false
for
index
,
v
:=
range
expect
{
...
...
@@ -331,8 +363,6 @@ func MatchScene(expect, actual, langType string) (pass bool) {
}
else
{
return
MatchScene
(
"l:"
+
expect
,
actual
,
langType
)
}
}
}
return
pass
return
false
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录