| 1636 | } |
| 1637 | |
| 1638 | func Test_getLen(t *testing.T) { |
| 1639 | falseCases := []interface{}{ |
| 1640 | nil, |
| 1641 | 0, |
| 1642 | true, |
| 1643 | false, |
| 1644 | 'A', |
| 1645 | struct{}{}, |
| 1646 | } |
| 1647 | for _, v := range falseCases { |
| 1648 | l, ok := getLen(v) |
| 1649 | False(t, ok, "Expected getLen fail to get length of %#v", v) |
| 1650 | Equal(t, 0, l, "getLen should return 0 for %#v", v) |
| 1651 | } |
| 1652 | |
| 1653 | ch := make(chan int, 5) |
| 1654 | ch <- 1 |
| 1655 | ch <- 2 |
| 1656 | ch <- 3 |
| 1657 | trueCases := []struct { |
| 1658 | v interface{} |
| 1659 | l int |
| 1660 | }{ |
| 1661 | {[]int{1, 2, 3}, 3}, |
| 1662 | {[...]int{1, 2, 3}, 3}, |
| 1663 | {"ABC", 3}, |
| 1664 | {map[int]int{1: 2, 2: 4, 3: 6}, 3}, |
| 1665 | {ch, 3}, |
| 1666 | |
| 1667 | {[]int{}, 0}, |
| 1668 | {map[int]int{}, 0}, |
| 1669 | {make(chan int), 0}, |
| 1670 | |
| 1671 | {[]int(nil), 0}, |
| 1672 | {map[int]int(nil), 0}, |
| 1673 | {(chan int)(nil), 0}, |
| 1674 | } |
| 1675 | |
| 1676 | for _, c := range trueCases { |
| 1677 | l, ok := getLen(c.v) |
| 1678 | True(t, ok, "Expected getLen success to get length of %#v", c.v) |
| 1679 | Equal(t, c.l, l) |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | func TestLen(t *testing.T) { |
| 1684 | mockT := new(testing.T) |