MCPcopy
hub / github.com/golang/tools / TestFixInit

Function TestFixInit

gopls/internal/cache/parsego/parse_test.go:136–246  ·  view source on GitHub ↗

TestFixInit tests the init stmt after if/for/switch which is put under cond after parsing will be fixed and moved to Init.

(t *testing.T)

Source from the content-addressed store, hash-verified

134// TestFixInit tests the init stmt after if/for/switch which is put under cond after parsing
135// will be fixed and moved to Init.
136func TestFixInit(t *testing.T) {
137 var testCases = []struct {
138 name string
139 source string
140 fixes []parsego.FixType
141 wantInitFix string
142 }{
143 {
144 name: "simple define",
145 source: "i := 0",
146 fixes: []parsego.FixType{parsego.FixedInit},
147 wantInitFix: "i := 0",
148 },
149 {
150 name: "simple assign",
151 source: "i = 0",
152 fixes: []parsego.FixType{parsego.FixedInit},
153 wantInitFix: "i = 0",
154 },
155 {
156 name: "define with function call",
157 source: "i := f()",
158 fixes: []parsego.FixType{parsego.FixedInit},
159 wantInitFix: "i := f()",
160 },
161 {
162 name: "assign with function call",
163 source: "i = f()",
164 fixes: []parsego.FixType{parsego.FixedInit},
165 wantInitFix: "i = f()",
166 },
167 {
168 name: "assign with receiving chan",
169 source: "i = <-ch",
170 fixes: []parsego.FixType{parsego.FixedInit},
171 wantInitFix: "i = <-ch",
172 },
173
174 // fixInitStmt won't fix the following cases.
175 {
176 name: "call in if",
177 source: `fmt.Println("helloworld")`,
178 fixes: nil,
179 },
180 {
181 name: "receive chan",
182 source: `<- ch`,
183 fixes: nil,
184 },
185 }
186
187 // currently, switch will leave its Tag empty after fix because it allows empty,
188 // and if and for will leave an underscore in Cond.
189 getWantCond := func(keyword string) string {
190 if keyword == "switch" {
191 return ""
192 }
193 return "_"

Callers

nothing calls this directly

Calls 10

ParseFunction · 0.92
FileSetForFunction · 0.92
FormatFunction · 0.92
filesrcFunction · 0.85
ensureSourceFunction · 0.85
inspectFunction · 0.85
infoFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
FatalfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…