(t *testing.T)
| 1358 | } |
| 1359 | |
| 1360 | func TestExpression_Value(t *testing.T) { |
| 1361 | src := `{ |
| 1362 | "string": "string_val", |
| 1363 | "number": 5, |
| 1364 | "bool_true": true, |
| 1365 | "bool_false": false, |
| 1366 | "array": ["a"], |
| 1367 | "object": {"key": "value"}, |
| 1368 | "null": null |
| 1369 | }` |
| 1370 | expected := map[string]cty.Value{ |
| 1371 | "string": cty.StringVal("string_val"), |
| 1372 | "number": cty.NumberIntVal(5), |
| 1373 | "bool_true": cty.BoolVal(true), |
| 1374 | "bool_false": cty.BoolVal(false), |
| 1375 | "array": cty.TupleVal([]cty.Value{cty.StringVal("a")}), |
| 1376 | "object": cty.ObjectVal(map[string]cty.Value{ |
| 1377 | "key": cty.StringVal("value"), |
| 1378 | }), |
| 1379 | "null": cty.NullVal(cty.DynamicPseudoType), |
| 1380 | } |
| 1381 | |
| 1382 | file, diags := Parse([]byte(src), "") |
| 1383 | if len(diags) != 0 { |
| 1384 | t.Errorf("got %d diagnostics on parse; want 0", len(diags)) |
| 1385 | for _, diag := range diags { |
| 1386 | t.Logf("- %s", diag.Error()) |
| 1387 | } |
| 1388 | } |
| 1389 | if file == nil { |
| 1390 | t.Fatalf("got nil File; want actual file") |
| 1391 | } |
| 1392 | if file.Body == nil { |
| 1393 | t.Fatalf("got nil Body; want actual body") |
| 1394 | } |
| 1395 | attrs, diags := file.Body.JustAttributes() |
| 1396 | if len(diags) != 0 { |
| 1397 | t.Errorf("got %d diagnostics on decode; want 0", len(diags)) |
| 1398 | for _, diag := range diags { |
| 1399 | t.Logf("- %s", diag.Error()) |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | for ek, ev := range expected { |
| 1404 | val, diags := attrs[ek].Expr.Value(&hcl.EvalContext{}) |
| 1405 | if len(diags) != 0 { |
| 1406 | t.Errorf("got %d diagnostics on eval; want 0", len(diags)) |
| 1407 | for _, diag := range diags { |
| 1408 | t.Logf("- %s", diag.Error()) |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | if !val.RawEquals(ev) { |
| 1413 | t.Errorf("wrong result %#v; want %#v", val, ev) |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | } |
nothing calls this directly
no test coverage detected