util: fix a bug with not copying slice of len=1 in ArrayReverse
ArrayReverse copies it's argument only if it's len is > 1. It needs to be consistent in all cases.
This commit is contained in:
parent
d07d6f3371
commit
24bb66e606
2 changed files with 10 additions and 5 deletions
|
@ -30,7 +30,16 @@ var testCases = []struct {
|
|||
|
||||
func TestArrayReverse(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
have := ArrayReverse(tc.arr)
|
||||
arg := make([]byte, len(tc.arr))
|
||||
copy(arg, tc.arr)
|
||||
|
||||
have := ArrayReverse(arg)
|
||||
require.Equal(t, tc.rev, have)
|
||||
|
||||
// test that argument was copied
|
||||
for i := range have {
|
||||
have[i] = ^have[i]
|
||||
}
|
||||
require.Equal(t, tc.arr, arg)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue