-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregression_test.go
More file actions
35 lines (31 loc) · 1.05 KB
/
Copy pathregression_test.go
File metadata and controls
35 lines (31 loc) · 1.05 KB
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
// Copyright 2022 The golang.design Initiative Authors. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package reflect
import "testing"
// TestDeepCopyNilPointer is a regression test for golang-design/reflect#2:
// copying a nil pointer must yield a nil pointer, not a non-nil pointer to a
// zero value.
func TestDeepCopyNilPointer(t *testing.T) {
type ListNode struct {
Val int
Next *ListNode
}
var src *ListNode
if dst := DeepCopy(src); dst != nil {
t.Fatalf("DeepCopy(nil pointer) = %#v, want nil", dst)
}
}
// TestDeepCopyBidirectionalChan guards the copyChan fix: a bidirectional
// channel must be replaced by a freshly created channel, not aliased to the
// source channel.
func TestDeepCopyBidirectionalChan(t *testing.T) {
src := make(chan int, 1)
dst := DeepCopy(src)
if dst == src {
t.Fatal("DeepCopy(bidirectional chan) aliased the source channel, want a new channel")
}
if cap(dst) != cap(src) {
t.Fatalf("DeepCopy chan cap = %d, want %d", cap(dst), cap(src))
}
}