aboutsummaryrefslogtreecommitdiff
path: root/lib/sliceutil/sliceutil_test.go
blob: 41387cd2bae9a5acb8265f8ad208d35636eb4040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (C) 2023 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package sliceutil_test

import (
	"testing"

	"github.com/syncthing/syncthing/lib/sliceutil"
	"golang.org/x/exp/slices"
)

func TestRemoveAndZero(t *testing.T) {
	a := []int{1, 2, 3, 4, 5}
	b := sliceutil.RemoveAndZero(a, 2)
	exp := []int{1, 2, 4, 5}
	if !slices.Equal(b, exp) {
		t.Errorf("got %v, expected %v", b, exp)
	}
	for _, e := range a {
		if e == 3 {
			t.Errorf("element should have been zeroed")
		}
	}
}