Skip to content

Commit b994304

Browse files
committed
linter, use same assert fmt string
1 parent 162879b commit b994304

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

assert/assert.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ var (
143143

144144
const (
145145
assertionMsg = "assertion violation"
146+
gotWantFmt = ": got '%v', want '%v'"
146147
)
147148

148149
// PushTester sets the current testing context for default asserter. This must
@@ -356,7 +357,7 @@ func NotEqual[T comparable](val, want T, a ...any) {
356357
// Asserter) with the given message.
357358
func Equal[T comparable](val, want T, a ...any) {
358359
if want != val {
359-
defMsg := fmt.Sprintf(assertionMsg+": got '%v', want '%v'", val, want)
360+
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, val, want)
360361
Default().reportAssertionFault(defMsg, a...)
361362
}
362363
}
@@ -365,7 +366,7 @@ func Equal[T comparable](val, want T, a ...any) {
365366
// panics/errors (current Asserter) with the given message.
366367
func DeepEqual(val, want any, a ...any) {
367368
if !reflect.DeepEqual(val, want) {
368-
defMsg := fmt.Sprintf(assertionMsg+": got '%v', want '%v'", val, want)
369+
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, val, want)
369370
Default().reportAssertionFault(defMsg, a...)
370371
}
371372
}
@@ -390,7 +391,7 @@ func Len(obj string, length int, a ...any) {
390391
l := len(obj)
391392

392393
if l != length {
393-
defMsg := fmt.Sprintf(assertionMsg+": got '%d', want '%d'", l, length)
394+
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
394395
Default().reportAssertionFault(defMsg, a...)
395396
}
396397
}
@@ -403,7 +404,7 @@ func SLen[S ~[]T, T any](obj S, length int, a ...any) {
403404
l := len(obj)
404405

405406
if l != length {
406-
defMsg := fmt.Sprintf(assertionMsg+": got '%d', want '%d'", l, length)
407+
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
407408
Default().reportAssertionFault(defMsg, a...)
408409
}
409410
}
@@ -416,7 +417,7 @@ func MLen[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {
416417
l := len(obj)
417418

418419
if l != length {
419-
defMsg := fmt.Sprintf(assertionMsg+": got '%d', want '%d'", l, length)
420+
defMsg := fmt.Sprintf(assertionMsg+gotWantFmt, l, length)
420421
Default().reportAssertionFault(defMsg, a...)
421422
}
422423
}

0 commit comments

Comments
 (0)