Skip to content

Commit 9783d40

Browse files
committed
refactor: use %q to simplify fmt.Sprintf
1 parent 07bac60 commit 9783d40

7 files changed

+9
-9
lines changed

assert/assertion_compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedCompare
468468

469469
compareResult, isComparable := compare(e1, e2, e1Kind)
470470
if !isComparable {
471-
return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...)
471+
return Fail(t, fmt.Sprintf("Can not compare type %q", reflect.TypeOf(e1)), msgAndArgs...)
472472
}
473473

474474
if !containsValue(allowedComparesResults, compareResult) {

assert/assertion_order.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareR
3333
compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind)
3434

3535
if !isComparable {
36-
return Fail(t, fmt.Sprintf("Can not compare type \"%s\" and \"%s\"", reflect.TypeOf(value), reflect.TypeOf(prevValue)), msgAndArgs...)
36+
return Fail(t, fmt.Sprintf("Can not compare type %q and %q", reflect.TypeOf(value), reflect.TypeOf(prevValue)), msgAndArgs...)
3737
}
3838

3939
if !containsValue(allowedComparesResults, compareResult) {

assert/assertions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})
10691069
element := subsetList.Index(i).Interface()
10701070
ok, found := containsElement(list, element)
10711071
if !ok {
1072-
return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", list), msgAndArgs...)
1072+
return Fail(t, fmt.Sprintf("%q could not be applied builtin len()", list), msgAndArgs...)
10731073
}
10741074
if !found {
10751075
return true

assert/assertions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ func TestRegexp(t *testing.T) {
21182118
}
21192119

21202120
for _, tc := range cases {
2121-
False(t, Regexp(mockT, tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str)
2121+
False(t, Regexp(mockT, tc.rx, tc.str), "Expected %q to not match %q", tc.rx, tc.str)
21222122
False(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str))
21232123
False(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str)))
21242124
True(t, NotRegexp(mockT, tc.rx, tc.str))

assert/forward_assertions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func TestRegexpWrapper(t *testing.T) {
546546
}
547547

548548
for _, tc := range cases {
549-
False(t, assert.Regexp(tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str)
549+
False(t, assert.Regexp(tc.rx, tc.str), "Expected %q to not match %q", tc.rx, tc.str)
550550
False(t, assert.Regexp(regexp.MustCompile(tc.rx), tc.str))
551551
True(t, assert.NotRegexp(tc.rx, tc.str))
552552
True(t, assert.NotRegexp(regexp.MustCompile(tc.rx), tc.str))

assert/http_assertions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string,
138138

139139
contains := strings.Contains(body, fmt.Sprint(str))
140140
if !contains {
141-
Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...)
141+
Fail(t, fmt.Sprintf("Expected response body for %q to contain %q but found %q", url+"?"+values.Encode(), str, body), msgAndArgs...)
142142
}
143143

144144
return contains
@@ -158,7 +158,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url strin
158158

159159
contains := strings.Contains(body, fmt.Sprint(str))
160160
if contains {
161-
Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body), msgAndArgs...)
161+
Fail(t, fmt.Sprintf("Expected response body for %q to NOT contain %q but found %q", url+"?"+values.Encode(), str, body), msgAndArgs...)
162162
}
163163

164164
return !contains

mock/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
494494
// expected call found, but it has already been called with repeatable times
495495
if call != nil {
496496
m.mutex.Unlock()
497-
m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(\"%s\").Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo())
497+
m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(%q).Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo())
498498
}
499499
// we have to fail here - because we don't know what to do
500500
// as the return arguments. This is because:
@@ -514,7 +514,7 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen
514514
assert.CallerInfo(),
515515
)
516516
} else {
517-
m.fail("\nassert: mock: I don't know what to return because the method call was unexpected.\n\tEither do Mock.On(\"%s\").Return(...) first, or remove the %s() call.\n\tThis method was unexpected:\n\t\t%s\n\tat: %s", methodName, methodName, callString(methodName, arguments, true), assert.CallerInfo())
517+
m.fail("\nassert: mock: I don't know what to return because the method call was unexpected.\n\tEither do Mock.On(%q).Return(...) first, or remove the %s() call.\n\tThis method was unexpected:\n\t\t%s\n\tat: %s", methodName, methodName, callString(methodName, arguments, true), assert.CallerInfo())
518518
}
519519
}
520520

0 commit comments

Comments
 (0)