mirror of https://github.com/stretchr/testify.git
assert: shorten cases
parent
f7fedd9f85
commit
f6ed021e60
|
@ -1661,77 +1661,35 @@ func TestLen(t *testing.T) {
|
|||
ch <- 3
|
||||
|
||||
cases := []struct {
|
||||
v interface{}
|
||||
l int
|
||||
}{
|
||||
{[]int{1, 2, 3}, 3},
|
||||
{[...]int{1, 2, 3}, 3},
|
||||
{"ABC", 3},
|
||||
{map[int]int{1: 2, 2: 4, 3: 6}, 3},
|
||||
{ch, 3},
|
||||
|
||||
{[]int{}, 0},
|
||||
{map[int]int{}, 0},
|
||||
{make(chan int), 0},
|
||||
|
||||
{[]int(nil), 0},
|
||||
{map[int]int(nil), 0},
|
||||
{(chan int)(nil), 0},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
True(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l)
|
||||
}
|
||||
|
||||
cases = []struct {
|
||||
v interface{}
|
||||
l int
|
||||
}{
|
||||
{[]int{1, 2, 3}, 4},
|
||||
{[...]int{1, 2, 3}, 2},
|
||||
{"ABC", 2},
|
||||
{map[int]int{1: 2, 2: 4, 3: 6}, 4},
|
||||
{ch, 2},
|
||||
|
||||
{[]int{}, 1},
|
||||
{map[int]int{}, 1},
|
||||
{make(chan int), 1},
|
||||
|
||||
{[]int(nil), 1},
|
||||
{map[int]int(nil), 1},
|
||||
{(chan int)(nil), 1},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
False(t, Len(mockT, c.v, c.l), "%#v have %d items", c.v, c.l)
|
||||
}
|
||||
|
||||
formatCases := []struct {
|
||||
in interface{}
|
||||
wantLen int
|
||||
want string
|
||||
v interface{}
|
||||
l int
|
||||
format string
|
||||
}{
|
||||
{[]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]"},
|
||||
{ch, 3, ""},
|
||||
|
||||
{[]int{}, 0, "[]"},
|
||||
{map[int]int{}, 0, "map[]"},
|
||||
{make(chan int), 0, ""},
|
||||
|
||||
{[]int(nil), 0, "[]"},
|
||||
{map[int]int(nil), 0, "map[]"},
|
||||
{(chan int)(nil), 0, "<nil>"},
|
||||
}
|
||||
|
||||
t.Run("Len() error message formatting", func(t *testing.T) {
|
||||
for _, tt := range formatCases {
|
||||
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 != "" {
|
||||
msgMock := new(mockTestingT)
|
||||
Len(msgMock, tt.in, 1234567)
|
||||
want := fmt.Sprintf(`"%s" should have 1234567 item(s), but has %d`, tt.want, tt.wantLen)
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithinDuration(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue