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