From ab9aa4a7e6d792c70caeda94ba65e78d7b4d5317 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Tue, 24 Oct 2023 13:32:19 -0700 Subject: [PATCH] try to do the whole format string --- assert/assertions_test.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 36a19a144..346e101b8 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -1644,33 +1644,32 @@ func TestLen(t *testing.T) { ch <- 3 cases := []struct { - v interface{} - l int - format string + v interface{} + l int + expected1234567 string // message when expecting 1234567 items }{ - {[]int{1, 2, 3}, 3, "[1 2 3]"}, - {[...]int{1, 2, 3}, 3, "[1 2 3]"}, - {"ABC", 3, "ABC"}, - {map[int]int{1: 2, 2: 4, 3: 6}, 3, "map[1:2 2:4 3:6]"}, + {[]int{1, 2, 3}, 3, `"[1 2 3]" should have 1234567 item(s), but has 3`}, + {[...]int{1, 2, 3}, 3, `"[1 2 3]" should have 1234567 item(s), but has 3`}, + {"ABC", 3, `"ABC" should have 1234567 item(s), but has 3`}, + {map[int]int{1: 2, 2: 4, 3: 6}, 3, `"map[1:2 2:4 3:6]" should have 1234567 item(s), but has 3`}, {ch, 3, ""}, - {[]int{}, 0, "[]"}, - {map[int]int{}, 0, "map[]"}, + {[]int{}, 0, `"[]" should have 1234567 item(s), but has 0`}, + {map[int]int{}, 0, `"map[]" should have 1234567 item(s), but has 0`}, {make(chan int), 0, ""}, - {[]int(nil), 0, "[]"}, - {map[int]int(nil), 0, "map[]"}, - {(chan int)(nil), 0, ""}, + {[]int(nil), 0, `"[]" should have 1234567 item(s), but has 0`}, + {map[int]int(nil), 0, `"map[]" should have 1234567 item(s), but has 0`}, + {(chan int)(nil), 0, `"" should have 1234567 item(s), but has 0`}, } for _, c := range cases { True(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l) False(t, Len(mockT, c.v, c.l+1), "%#v have %d items", c.v, c.l) - if c.format != "" { + if c.expected1234567 != "" { msgMock := new(mockTestingT) Len(msgMock, c.v, 1234567) - want := fmt.Sprintf(`"%s" should have 1234567 item(s), but has %d`, c.format, c.l) - Contains(t, msgMock.errorString(), want) + Contains(t, msgMock.errorString(), c.expected1234567) } } }