| 2136 | } |
| 2137 | |
| 2138 | func Test_getLen(t *testing.T) { |
| 2139 | t.Parallel() |
| 2140 | |
| 2141 | falseCases := []interface{}{ |
| 2142 | nil, |
| 2143 | 0, |
| 2144 | true, |
| 2145 | false, |
| 2146 | 'A', |
| 2147 | struct{}{}, |
| 2148 | } |
| 2149 | for _, v := range falseCases { |
| 2150 | l, ok := getLen(v) |
| 2151 | False(t, ok, "Expected getLen fail to get length of %#v", v) |
| 2152 | Equal(t, 0, l, "getLen should return 0 for %#v", v) |
| 2153 | } |
| 2154 | |
| 2155 | ch := make(chan int, 5) |
| 2156 | ch <- 1 |
| 2157 | ch <- 2 |
| 2158 | ch <- 3 |
| 2159 | trueCases := []struct { |
| 2160 | v interface{} |
| 2161 | l int |
| 2162 | }{ |
| 2163 | {[]int{1, 2, 3}, 3}, |
| 2164 | {[...]int{1, 2, 3}, 3}, |
| 2165 | {"ABC", 3}, |
| 2166 | {map[int]int{1: 2, 2: 4, 3: 6}, 3}, |
| 2167 | {ch, 3}, |
| 2168 | |
| 2169 | {[]int{}, 0}, |
| 2170 | {map[int]int{}, 0}, |
| 2171 | {make(chan int), 0}, |
| 2172 | |
| 2173 | {[]int(nil), 0}, |
| 2174 | {map[int]int(nil), 0}, |
| 2175 | {(chan int)(nil), 0}, |
| 2176 | } |
| 2177 | |
| 2178 | for _, c := range trueCases { |
| 2179 | l, ok := getLen(c.v) |
| 2180 | True(t, ok, "Expected getLen success to get length of %#v", c.v) |
| 2181 | Equal(t, c.l, l) |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | func TestLen(t *testing.T) { |
| 2186 | t.Parallel() |