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

Function TestAttributeAtPos

hclsyntax/structure_at_pos_test.go:176–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestAttributeAtPos(t *testing.T) {
177 tests := map[string]struct {
178 Src string
179 Pos hcl.Pos
180 WantName string
181 }{
182 "empty": {
183 ``,
184 hcl.Pos{Byte: 0},
185 "",
186 },
187 "top-level": {
188 `foo = 1`,
189 hcl.Pos{Byte: 0},
190 "foo",
191 },
192 "top-level with ignored sibling after": {
193 `
194 foo = 1
195 bar = 2
196 `,
197 hcl.Pos{Byte: 6},
198 "foo",
199 },
200 "top-level ignored sibling before": {
201 `
202 foo = 1
203 bar = 2
204 `,
205 hcl.Pos{Byte: 17},
206 "bar",
207 },
208 "nested": {
209 `
210 foo {
211 bar = 2
212 }
213 `,
214 hcl.Pos{Byte: 17},
215 "bar",
216 },
217 "nested in unterminated block": {
218 `
219 foo {
220 bar = 2
221 `,
222 hcl.Pos{Byte: 17},
223 "bar",
224 },
225 }
226
227 for name, test := range tests {
228 t.Run(name, func(t *testing.T) {
229 f, diags := ParseConfig([]byte(test.Src), "", hcl.Pos{Line: 1, Column: 1})
230 for _, diag := range diags {
231 // We intentionally ignore diagnostics here because we should be
232 // able to work with the incomplete configuration that results
233 // when the parser does its recovery behavior. However, we do

Callers

nothing calls this directly

Calls 4

RunMethod · 0.80
ParseConfigFunction · 0.70
AttributeAtPosMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected