-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone_test.go
52 lines (42 loc) · 891 Bytes
/
clone_test.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package slices2_test
import (
"testing"
"github.com/Pilatuz/slices2"
)
// TestClone unit tests for `clone` helper.
func TestClone(tt *testing.T) {
// string
tt.Run("str", func(t *testing.T) {
var Nil []string
Empty := []string{}
Foo := []string{"foo"}
FooBar := []string{"foo", "bar"}
test := func(a []string) {
t.Helper()
if b := slices2.Clone(a); same(a, b) || !equal(a, b) {
t.Errorf("clone(`%#v`)=`%#v`, expected `%#v`", a, b, a)
}
}
test(Nil)
test(Empty)
test(Foo)
test(FooBar)
})
// integer
tt.Run("int", func(t *testing.T) {
var Nil []int
Empty := []int{}
Foo := []int{123}
FooBar := []int{123, 456}
test := func(a []int) {
t.Helper()
if b := slices2.Clone(a); same(a, b) || !equal(a, b) {
t.Errorf("clone(`%#v`)=`%#v`, expected `%#v`", a, b, a)
}
}
test(Nil)
test(Empty)
test(Foo)
test(FooBar)
})
}