Skip to content

Commit

Permalink
try to do the whole format string
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinburkesegment committed Oct 31, 2023
1 parent 3b0cc42 commit ab9aa4a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<nil>"},
{[]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, `"<nil>" 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)
}
}
}
Expand Down

0 comments on commit ab9aa4a

Please sign in to comment.