Source file
src/cmd/fix/cftype_test.go
1
2
3
4
5 package main
6
7 func init() {
8 addTestCases(cftypeTests, cftypefix)
9 }
10
11 var cftypeTests = []testCase{
12 {
13 Name: "cftype.localVariable",
14 In: `package main
15
16 import "C"
17
18 func f() {
19 var x C.CFTypeRef = nil
20 x = nil
21 x, x = nil, nil
22 }
23 `,
24 Out: `package main
25
26 import "C"
27
28 func f() {
29 var x C.CFTypeRef = 0
30 x = 0
31 x, x = 0, 0
32 }
33 `,
34 },
35 {
36 Name: "cftype.globalVariable",
37 In: `package main
38
39 import "C"
40
41 var x C.CFTypeRef = nil
42
43 func f() {
44 x = nil
45 }
46 `,
47 Out: `package main
48
49 import "C"
50
51 var x C.CFTypeRef = 0
52
53 func f() {
54 x = 0
55 }
56 `,
57 },
58 {
59 Name: "cftype.EqualArgument",
60 In: `package main
61
62 import "C"
63
64 var x C.CFTypeRef
65 var y = x == nil
66 var z = x != nil
67 `,
68 Out: `package main
69
70 import "C"
71
72 var x C.CFTypeRef
73 var y = x == 0
74 var z = x != 0
75 `,
76 },
77 {
78 Name: "cftype.StructField",
79 In: `package main
80
81 import "C"
82
83 type T struct {
84 x C.CFTypeRef
85 }
86
87 var t = T{x: nil}
88 `,
89 Out: `package main
90
91 import "C"
92
93 type T struct {
94 x C.CFTypeRef
95 }
96
97 var t = T{x: 0}
98 `,
99 },
100 {
101 Name: "cftype.FunctionArgument",
102 In: `package main
103
104 import "C"
105
106 func f(x C.CFTypeRef) {
107 }
108
109 func g() {
110 f(nil)
111 }
112 `,
113 Out: `package main
114
115 import "C"
116
117 func f(x C.CFTypeRef) {
118 }
119
120 func g() {
121 f(0)
122 }
123 `,
124 },
125 {
126 Name: "cftype.ArrayElement",
127 In: `package main
128
129 import "C"
130
131 var x = [3]C.CFTypeRef{nil, nil, nil}
132 `,
133 Out: `package main
134
135 import "C"
136
137 var x = [3]C.CFTypeRef{0, 0, 0}
138 `,
139 },
140 {
141 Name: "cftype.SliceElement",
142 In: `package main
143
144 import "C"
145
146 var x = []C.CFTypeRef{nil, nil, nil}
147 `,
148 Out: `package main
149
150 import "C"
151
152 var x = []C.CFTypeRef{0, 0, 0}
153 `,
154 },
155 {
156 Name: "cftype.MapKey",
157 In: `package main
158
159 import "C"
160
161 var x = map[C.CFTypeRef]int{nil: 0}
162 `,
163 Out: `package main
164
165 import "C"
166
167 var x = map[C.CFTypeRef]int{0: 0}
168 `,
169 },
170 {
171 Name: "cftype.MapValue",
172 In: `package main
173
174 import "C"
175
176 var x = map[int]C.CFTypeRef{0: nil}
177 `,
178 Out: `package main
179
180 import "C"
181
182 var x = map[int]C.CFTypeRef{0: 0}
183 `,
184 },
185 {
186 Name: "cftype.Conversion1",
187 In: `package main
188
189 import "C"
190
191 var x C.CFTypeRef
192 var y = (*unsafe.Pointer)(&x)
193 `,
194 Out: `package main
195
196 import "C"
197
198 var x C.CFTypeRef
199 var y = (*unsafe.Pointer)(unsafe.Pointer(&x))
200 `,
201 },
202 {
203 Name: "cftype.Conversion2",
204 In: `package main
205
206 import "C"
207
208 var x unsafe.Pointer
209 var y = (*C.CFTypeRef)(&x)
210 `,
211 Out: `package main
212
213 import "C"
214
215 var x unsafe.Pointer
216 var y = (*C.CFTypeRef)(unsafe.Pointer(&x))
217 `,
218 },
219 }
220
View as plain text