MCPcopy
hub / github.com/hashicorp/hcl / TestTupleStatic

Function TestTupleStatic

hclsyntax/expression_static_test.go:56–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestTupleStatic(t *testing.T) {
57 expr, diags := ParseExpression([]byte(`[true, false]`), "", hcl.Pos{Line: 1, Column: 1})
58 exprs, moreDiags := hcl.ExprList(expr)
59 diags = append(diags, moreDiags...)
60 if len(diags) != 0 {
61 t.Errorf("wrong number of diags %d; want 0", len(diags))
62 for _, diag := range diags {
63 t.Logf("- %s", diag)
64 }
65 return
66 }
67
68 if got, want := len(exprs), 2; got != want {
69 t.Fatalf("wrong length %d; want %d", got, want)
70 }
71
72 got := make([]cty.Value, len(exprs))
73 want := []cty.Value{
74 cty.True,
75 cty.False,
76 }
77 for i, itemExpr := range exprs {
78 val, valDiags := itemExpr.Value(nil)
79 if len(valDiags) != 0 {
80 t.Errorf("wrong number of diags %d; want 0", len(valDiags))
81 for _, diag := range valDiags {
82 t.Logf("- %s", diag)
83 }
84 return
85 }
86 got[i] = val
87 }
88
89 for _, problem := range deep.Equal(got, want) {
90 t.Error(problem)
91 }
92}
93
94func TestMapStatic(t *testing.T) {
95 expr, diags := ParseExpression([]byte(`{"foo":true,"bar":false}`), "", hcl.Pos{Line: 1, Column: 1})

Callers

nothing calls this directly

Calls 5

EqualMethod · 0.80
ParseExpressionFunction · 0.70
ExprListMethod · 0.65
ValueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected