|
1 | 1 | package hclsyntax |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "testing" |
5 | 6 |
|
| 7 | + "github.com/google/go-cmp/cmp" |
6 | 8 | "github.com/hashicorp/hcl/v2" |
7 | 9 | "github.com/zclconf/go-cty/cty" |
8 | 10 | "github.com/zclconf/go-cty/cty/function" |
@@ -2269,3 +2271,77 @@ func TestStaticExpressionList(t *testing.T) { |
2269 | 2271 | t.Fatalf("wrong first value %#v; want cty.Zero", first.Val) |
2270 | 2272 | } |
2271 | 2273 | } |
| 2274 | + |
| 2275 | +// Check that function call w/ incomplete argument still reports correct range |
| 2276 | +func TestParseExpression_incompleteFunctionCall(t *testing.T) { |
| 2277 | + tests := []struct { |
| 2278 | + cfg string |
| 2279 | + expectedRange hcl.Range |
| 2280 | + }{ |
| 2281 | + { |
| 2282 | + `object({ foo = })`, |
| 2283 | + hcl.Range{ |
| 2284 | + Filename: "test.hcl", |
| 2285 | + Start: hcl.InitialPos, |
| 2286 | + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, |
| 2287 | + }, |
| 2288 | + }, |
| 2289 | + { |
| 2290 | + `object({ |
| 2291 | + foo = |
| 2292 | +})`, |
| 2293 | + hcl.Range{ |
| 2294 | + Filename: "test.hcl", |
| 2295 | + Start: hcl.InitialPos, |
| 2296 | + End: hcl.Pos{Line: 3, Column: 3, Byte: 19}, |
| 2297 | + }, |
| 2298 | + }, |
| 2299 | + { |
| 2300 | + `object({ foo = }`, |
| 2301 | + hcl.Range{ |
| 2302 | + Filename: "test.hcl", |
| 2303 | + Start: hcl.InitialPos, |
| 2304 | + End: hcl.Pos{Line: 0, Column: 0, Byte: 0}, |
| 2305 | + }, |
| 2306 | + }, |
| 2307 | + { |
| 2308 | + `object({ |
| 2309 | + foo = |
| 2310 | +}`, |
| 2311 | + hcl.Range{ |
| 2312 | + Filename: "test.hcl", |
| 2313 | + Start: hcl.InitialPos, |
| 2314 | + End: hcl.Pos{Line: 0, Column: 0, Byte: 0}, |
| 2315 | + }, |
| 2316 | + }, |
| 2317 | + { |
| 2318 | + `object({ |
| 2319 | + foo = |
| 2320 | +`, |
| 2321 | + hcl.Range{ |
| 2322 | + Filename: "test.hcl", |
| 2323 | + Start: hcl.InitialPos, |
| 2324 | + End: hcl.Pos{Line: 0, Column: 0, Byte: 0}, |
| 2325 | + }, |
| 2326 | + }, |
| 2327 | + { |
| 2328 | + `object({ |
| 2329 | + foo = |
| 2330 | +)`, |
| 2331 | + hcl.Range{ |
| 2332 | + Filename: "test.hcl", |
| 2333 | + Start: hcl.InitialPos, |
| 2334 | + End: hcl.Pos{Line: 0, Column: 0, Byte: 0}, |
| 2335 | + }, |
| 2336 | + }, |
| 2337 | + } |
| 2338 | + |
| 2339 | + for i, tc := range tests { |
| 2340 | + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { |
| 2341 | + expr, _ := ParseExpression([]byte(tc.cfg), "test.hcl", hcl.InitialPos) |
| 2342 | + if diff := cmp.Diff(tc.expectedRange, expr.Range()); diff != "" { |
| 2343 | + t.Fatalf("range mismatch: %s", diff) |
| 2344 | + } |
| 2345 | + }) |
| 2346 | + } |
| 2347 | +} |
0 commit comments