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

Function TestParseWithStartPos

json/public_test.go:120–188  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestParseWithStartPos(t *testing.T) {
121 src := `{
122 "foo": {
123 "bar": "baz"
124 }
125}`
126 part := `{
127 "bar": "baz"
128 }`
129
130 file, diags := Parse([]byte(src), "")
131 partFile, partDiags := ParseWithStartPos([]byte(part), "", hcl.Pos{Byte: 0, Line: 2, Column: 10})
132 if len(diags) != 0 {
133 t.Errorf("got %d diagnostics on parse src; want 0", len(diags))
134 for _, diag := range diags {
135 t.Logf("- %s", diag.Error())
136 }
137 }
138 if len(partDiags) != 0 {
139 t.Errorf("got %d diagnostics on parse part src; want 0", len(partDiags))
140 for _, diag := range partDiags {
141 t.Logf("- %s", diag.Error())
142 }
143 }
144
145 if file == nil {
146 t.Fatalf("got nil File; want actual file")
147 }
148 if file.Body == nil {
149 t.Fatalf("got nil Body; want actual body")
150 }
151 if partFile == nil {
152 t.Fatalf("got nil part File; want actual file")
153 }
154 if partFile.Body == nil {
155 t.Fatalf("got nil part Body; want actual body")
156 }
157
158 content, diags := file.Body.Content(&hcl.BodySchema{
159 Blocks: []hcl.BlockHeaderSchema{{Type: "foo"}},
160 })
161 if len(diags) != 0 {
162 t.Errorf("got %d diagnostics on decode; want 0", len(diags))
163 for _, diag := range diags {
164 t.Logf("- %s", diag.Error())
165 }
166 }
167 attrs, diags := content.Blocks[0].Body.JustAttributes()
168 if len(diags) != 0 {
169 t.Errorf("got %d diagnostics on decode; want 0", len(diags))
170 for _, diag := range diags {
171 t.Logf("- %s", diag.Error())
172 }
173 }
174 srcRange := attrs["bar"].Expr.Range()
175
176 partAttrs, diags := partFile.Body.JustAttributes()
177 if len(diags) != 0 {

Callers

nothing calls this directly

Calls 7

ParseFunction · 0.85
ParseWithStartPosFunction · 0.85
ContentMethod · 0.65
JustAttributesMethod · 0.65
RangeMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected