-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnative_test.go
More file actions
43 lines (35 loc) · 734 Bytes
/
native_test.go
File metadata and controls
43 lines (35 loc) · 734 Bytes
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
package deepcopy
import (
"testing"
"unsafe"
"github.com/stretchr/testify/assert"
)
func TestFuncCopy(t *testing.T) {
a := func(x int) int { return x + 1 }
var b func(x int) int
DeepCopy(&a, &b)
assert.Equal(t, a(1), b(1))
}
func TestUnsafePointerCopy(t *testing.T) {
i := 1
a := unsafe.Pointer(&i)
var b unsafe.Pointer
DeepCopy(&a, &b)
assert.Equal(t, a, b)
a = unsafe.Pointer(nil)
DeepCopy(&a, &b)
assert.Equal(t, a, b)
}
func TestChanCopy(t *testing.T) {
var a chan int = make(chan int, 9)
var b chan int = make(chan int, 98)
DeepCopy(&a, &b)
assert.Equal(t, a, b)
}
func TestUintptrCopy(t *testing.T) {
x := 1
a := uintptr(unsafe.Pointer(&x))
var b uintptr
DeepCopy(&a, &b)
assert.Equal(t, a, b)
}