mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
fix #1331: use str_eq to assert string and digit equality
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -158,6 +158,27 @@ func TestContainedBy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStringEqual(t *testing.T) {
|
||||
testData := []struct {
|
||||
raw interface{}
|
||||
expected interface{}
|
||||
}{
|
||||
{"abcd", "abcd"},
|
||||
{"0", 0},
|
||||
{"123", 123},
|
||||
// {"123.0", 123.0}, // FIXME
|
||||
{"12.3", 12.3},
|
||||
{"-12.3", -12.3},
|
||||
{"-123", -123},
|
||||
}
|
||||
|
||||
for _, data := range testData {
|
||||
if !assert.True(t, StringEqual(t, data.raw, data.expected)) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualFold(t *testing.T) {
|
||||
testData := []struct {
|
||||
raw interface{}
|
||||
expected interface{}
|
||||
@@ -168,7 +189,7 @@ func TestStringEqual(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, data := range testData {
|
||||
if !assert.True(t, StringEqual(t, data.raw, data.expected)) {
|
||||
if !assert.True(t, EqualFold(t, data.raw, data.expected)) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user