(t *testing.T)
| 886 | } |
| 887 | |
| 888 | func TestExtendReuseSlice(t *testing.T) { |
| 889 | tcs := []struct { |
| 890 | sz int |
| 891 | in []int |
| 892 | expected []int |
| 893 | }{ |
| 894 | { |
| 895 | sz: 0, |
| 896 | in: []int{1, 2, 3}, |
| 897 | expected: []int{}, |
| 898 | }, |
| 899 | { |
| 900 | sz: 2, |
| 901 | in: []int{1, 2, 3}, |
| 902 | expected: []int{1, 2}, |
| 903 | }, |
| 904 | { |
| 905 | sz: 5, |
| 906 | in: []int{1, 2, 3}, |
| 907 | expected: []int{1, 2, 3, 0, 0}, |
| 908 | }, |
| 909 | { |
| 910 | // len < cap < sz: slice was shrunk then grown past cap |
| 911 | sz: 6, |
| 912 | in: append(make([]int, 0, 4), 1, 2), |
| 913 | expected: []int{1, 2, 0, 0, 0, 0}, |
| 914 | }, |
| 915 | } |
| 916 | |
| 917 | for _, tc := range tcs { |
| 918 | t.Run(fmt.Sprintf("%v", tc.sz), func(t *testing.T) { |
| 919 | out := extendReuseSlice(tc.sz, tc.in) |
| 920 | assert.Equal(t, tc.expected, out) |
| 921 | }) |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | func BenchmarkExtendReuseSlice(b *testing.B) { |
| 926 | in := []int{1, 2, 3} |
nothing calls this directly
no test coverage detected