fix #1331: use str_eq to assert string and digit equality

This commit is contained in:
debugtalk
2022-06-03 23:29:03 +08:00
parent 174f07bac0
commit f1fd4a518d
5 changed files with 46 additions and 2 deletions
+7
View File
@@ -45,6 +45,7 @@ var Assertions = map[string]func(t assert.TestingT, actual interface{}, expected
"contained_by": ContainedBy,
"str_eq": StringEqual,
"string_equals": StringEqual,
"equal_fold": EqualFold,
"regex_match": RegexMatch,
}
@@ -157,6 +158,12 @@ func ContainedBy(t assert.TestingT, actual, expected interface{}, msgAndArgs ...
}
func StringEqual(t assert.TestingT, actual, expected interface{}, msgAndArgs ...interface{}) bool {
a := fmt.Sprintf("%v", actual)
e := fmt.Sprintf("%v", expected)
return assert.True(t, a == e, msgAndArgs)
}
func EqualFold(t assert.TestingT, actual, expected interface{}, msgAndArgs ...interface{}) bool {
if !assert.IsType(t, "string", actual, msgAndArgs) {
return false
}