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

Function TestMapStatic

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

Source from the content-addressed store, hash-verified

92}
93
94func TestMapStatic(t *testing.T) {
95 expr, diags := ParseExpression([]byte(`{"foo":true,"bar":false}`), "", hcl.Pos{Line: 1, Column: 1})
96 items, moreDiags := hcl.ExprMap(expr)
97 diags = append(diags, moreDiags...)
98 if len(diags) != 0 {
99 t.Errorf("wrong number of diags %d; want 0", len(diags))
100 for _, diag := range diags {
101 t.Logf("- %s", diag)
102 }
103 return
104 }
105
106 if got, want := len(items), 2; got != want {
107 t.Fatalf("wrong length %d; want %d", got, want)
108 }
109
110 got := make(map[cty.Value]cty.Value)
111 want := map[cty.Value]cty.Value{
112 cty.StringVal("foo"): cty.True,
113 cty.StringVal("bar"): cty.False,
114 }
115 for _, item := range items {
116 var itemDiags hcl.Diagnostics
117 key, keyDiags := item.Key.Value(nil)
118 itemDiags = append(itemDiags, keyDiags...)
119 val, valDiags := item.Value.Value(nil)
120 itemDiags = append(itemDiags, valDiags...)
121 if len(itemDiags) != 0 {
122 t.Errorf("wrong number of diags %d; want 0", len(itemDiags))
123 for _, diag := range itemDiags {
124 t.Logf("- %s", diag)
125 }
126 return
127 }
128 got[key] = val
129 }
130
131 for _, problem := range deep.Equal(got, want) {
132 t.Error(problem)
133 }
134}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected