-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy paththread_local_map_entry_test.go
165 lines (142 loc) · 3.8 KB
/
thread_local_map_entry_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package routine
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEntry_Clone(t *testing.T) {
expect := &personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value := entryValue[*personCloneable](e)
assert.NotNil(t, value)
assert.Equal(t, *expect, *value)
//
c, ok := entryAssert[Cloneable](e)
assert.True(t, ok)
assert.Equal(t, *expect, *c.(*personCloneable))
//
copied := entry(c.Clone())
value2 := entryValue[*personCloneable](copied)
assert.NotNil(t, value2)
assert.Equal(t, *expect, *value2)
//
c3, ok2 := entryAssert[Cloneable](copied)
assert.True(t, ok2)
assert.Equal(t, *expect, *c3.(*personCloneable))
}
//===
func TestEntry_Value_Nil(t *testing.T) {
e := entry(nil)
value := entryValue[any](e)
assert.Nil(t, value)
}
func TestEntry_Value_NotNil(t *testing.T) {
expect := 1
e := entry(expect)
value := entryValue[int](e)
assert.Equal(t, expect, value)
}
func TestEntry_Value_Default(t *testing.T) {
expect := 0
e := entry(expect)
value := entryValue[int](e)
assert.Equal(t, expect, value)
}
func TestEntry_Value_Interface_Nil(t *testing.T) {
var expect Cloneable
e := entry(expect)
value := entryValue[Cloneable](e)
assert.Nil(t, value)
}
func TestEntry_Value_Interface_NotNil(t *testing.T) {
var expect Cloneable = &personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value := entryValue[Cloneable](e)
assert.Same(t, expect, value)
}
func TestEntry_Value_Pointer_Nil(t *testing.T) {
var expect *personCloneable
e := entry(expect)
value := entryValue[*personCloneable](e)
assert.Nil(t, value)
}
func TestEntry_Value_Pointer_NotNil(t *testing.T) {
expect := &personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value := entryValue[*personCloneable](e)
assert.Same(t, expect, value)
}
func TestEntry_Value_Struct_Default(t *testing.T) {
expect := personCloneable{}
e := entry(expect)
value := entryValue[personCloneable](e)
assert.Equal(t, expect, value)
}
func TestEntry_Value_Struct_NotDefault(t *testing.T) {
expect := personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value := entryValue[personCloneable](e)
assert.Equal(t, expect, value)
}
//===
func TestEntry_Assert_Nil(t *testing.T) {
e := entry(nil)
value, ok := entryAssert[any](e)
assert.False(t, ok)
assert.Nil(t, value)
}
func TestEntry_Assert_NotNil(t *testing.T) {
expect := 1
e := entry(expect)
value, ok := entryAssert[int](e)
assert.True(t, ok)
assert.Equal(t, expect, value)
}
func TestEntry_Assert_Default(t *testing.T) {
expect := 0
e := entry(expect)
value, ok := entryAssert[int](e)
assert.True(t, ok)
assert.Equal(t, expect, value)
}
func TestEntry_Assert_Interface_Nil(t *testing.T) {
var expect Cloneable
e := entry(expect)
value, ok := entryAssert[Cloneable](e)
assert.False(t, ok)
assert.Nil(t, value)
}
func TestEntry_Assert_Interface_NotNil(t *testing.T) {
var expect Cloneable = &personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value, ok := entryAssert[Cloneable](e)
assert.True(t, ok)
assert.Same(t, expect, value)
}
func TestEntry_Assert_Pointer_Nil(t *testing.T) {
var expect *personCloneable
e := entry(expect)
value, ok := entryAssert[*personCloneable](e)
assert.True(t, ok)
assert.Nil(t, value)
}
func TestEntry_Assert_Pointer_NotNil(t *testing.T) {
expect := &personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value, ok := entryAssert[*personCloneable](e)
assert.True(t, ok)
assert.Same(t, expect, value)
}
func TestEntry_Assert_Struct_Default(t *testing.T) {
expect := personCloneable{}
e := entry(expect)
value, ok := entryAssert[personCloneable](e)
assert.True(t, ok)
assert.Equal(t, expect, value)
}
func TestEntry_Assert_Struct_NotDefault(t *testing.T) {
expect := personCloneable{Id: 1, Name: "Hello"}
e := entry(expect)
value, ok := entryAssert[personCloneable](e)
assert.True(t, ok)
assert.Equal(t, expect, value)
}