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

Function checkTraversalsMatch

cmd/hclspecsuite/traversals.go:71–120  ·  view source on GitHub ↗

checkTraversalsMatch determines if a given traversal matches the given expectation, which must've been produced by an earlier call to findTraversalSpec for the same traversal.

(got hcl.Traversal, filename string, match *TestFileExpectTraversal)

Source from the content-addressed store, hash-verified

69// expectation, which must've been produced by an earlier call to
70// findTraversalSpec for the same traversal.
71func checkTraversalsMatch(got hcl.Traversal, filename string, match *TestFileExpectTraversal) hcl.Diagnostics {
72 var diags hcl.Diagnostics
73
74 gotRng := got.SourceRange()
75 wantRng := match.Range
76
77 if got, want := gotRng.Filename, filename; got != want {
78 diags = append(diags, &hcl.Diagnostic{
79 Severity: hcl.DiagError,
80 Summary: "Incorrect filename in detected traversal",
81 Detail: fmt.Sprintf(
82 "Filename was reported as %q, but was expecting %q.",
83 got, want,
84 ),
85 Subject: match.Traversal.SourceRange().Ptr(),
86 })
87 return diags
88 }
89
90 // If we have the expected filename then we'll use that to construct the
91 // full "want range" here so that we can use it to point to the appropriate
92 // location in the remaining diagnostics.
93 wantRng.Filename = filename
94
95 if got, want := gotRng.Start, wantRng.Start; got != want {
96 diags = append(diags, &hcl.Diagnostic{
97 Severity: hcl.DiagError,
98 Summary: "Incorrect start position in detected traversal",
99 Detail: fmt.Sprintf(
100 "Start position was reported as line %d column %d byte %d, but was expecting line %d column %d byte %d.",
101 got.Line, got.Column, got.Byte,
102 want.Line, want.Column, want.Byte,
103 ),
104 Subject: &wantRng,
105 })
106 }
107 if got, want := gotRng.End, wantRng.End; got != want {
108 diags = append(diags, &hcl.Diagnostic{
109 Severity: hcl.DiagError,
110 Summary: "Incorrect end position in detected traversal",
111 Detail: fmt.Sprintf(
112 "End position was reported as line %d column %d byte %d, but was expecting line %d column %d byte %d.",
113 got.Line, got.Column, got.Byte,
114 want.Line, want.Column, want.Byte,
115 ),
116 Subject: &wantRng,
117 })
118 }
119 return diags
120}

Callers 1

runTestInputMethod · 0.85

Calls 2

PtrMethod · 0.80
SourceRangeMethod · 0.65

Tested by

no test coverage detected