(t *testing.T)
| 257 | } |
| 258 | |
| 259 | func TestOutermostExprAtPos(t *testing.T) { |
| 260 | tests := map[string]struct { |
| 261 | Src string |
| 262 | Pos hcl.Pos |
| 263 | WantSrc string |
| 264 | }{ |
| 265 | "empty": { |
| 266 | ``, |
| 267 | hcl.Pos{Byte: 0}, |
| 268 | ``, |
| 269 | }, |
| 270 | "simple bool": { |
| 271 | `a = true`, |
| 272 | hcl.Pos{Byte: 6}, |
| 273 | `true`, |
| 274 | }, |
| 275 | "simple reference": { |
| 276 | `a = blah`, |
| 277 | hcl.Pos{Byte: 6}, |
| 278 | `blah`, |
| 279 | }, |
| 280 | "attribute reference": { |
| 281 | `a = blah.foo`, |
| 282 | hcl.Pos{Byte: 6}, |
| 283 | `blah.foo`, |
| 284 | }, |
| 285 | "parens": { |
| 286 | `a = (1 + 1)`, |
| 287 | hcl.Pos{Byte: 6}, |
| 288 | `(1 + 1)`, |
| 289 | }, |
| 290 | "tuple cons": { |
| 291 | `a = [1, 2, 3]`, |
| 292 | hcl.Pos{Byte: 5}, |
| 293 | `[1, 2, 3]`, |
| 294 | }, |
| 295 | "function call": { |
| 296 | `a = foom("a")`, |
| 297 | hcl.Pos{Byte: 10}, |
| 298 | `foom("a")`, |
| 299 | }, |
| 300 | } |
| 301 | |
| 302 | for name, test := range tests { |
| 303 | t.Run(name, func(t *testing.T) { |
| 304 | inputSrc := []byte(test.Src) |
| 305 | f, diags := ParseConfig(inputSrc, "", hcl.Pos{Line: 1, Column: 1}) |
| 306 | for _, diag := range diags { |
| 307 | // We intentionally ignore diagnostics here because we should be |
| 308 | // able to work with the incomplete configuration that results |
| 309 | // when the parser does its recovery behavior. However, we do |
| 310 | // log them in case it's helpful to someone debugging a failing |
| 311 | // test. |
| 312 | t.Log(diag.Error()) |
| 313 | } |
| 314 | |
| 315 | gotExpr := f.OutermostExprAtPos(test.Pos) |
| 316 | var gotSrc string |
nothing calls this directly
no test coverage detected