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)
| 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. |
| 136 | func 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 "_" |
nothing calls this directly
no test coverage detected
searching dependent graphs…