sliceutil_test.go 652 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2023 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package sliceutil_test
  7. import (
  8. "slices"
  9. "testing"
  10. "github.com/syncthing/syncthing/lib/sliceutil"
  11. )
  12. func TestRemoveAndZero(t *testing.T) {
  13. a := []int{1, 2, 3, 4, 5}
  14. b := sliceutil.RemoveAndZero(a, 2)
  15. exp := []int{1, 2, 4, 5}
  16. if !slices.Equal(b, exp) {
  17. t.Errorf("got %v, expected %v", b, exp)
  18. }
  19. for _, e := range a {
  20. if e == 3 {
  21. t.Errorf("element should have been zeroed")
  22. }
  23. }
  24. }