MCPcopy
hub / github.com/carvel-dev/ytt / TestParserMapArray

Function TestParserMapArray

pkg/yamlmeta/parser_test.go:261–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

259}
260
261func TestParserMapArray(t *testing.T) {
262 const data = `---
263array:
264- 1
265- 2
266- key: value
267`
268
269 parsedVal, err := yamlmeta.NewParser(yamlmeta.ParserOpts{WithoutComments: false}).ParseBytes([]byte(data), "")
270 if err != nil {
271 t.Fatalf("error: %s", err)
272 }
273
274 expectedVal := yamlmeta.NewDocumentSet(&yamlmeta.DocumentSetProto{
275 Items: []*yamlmeta.DocumentProto{
276 &yamlmeta.DocumentProto{
277 Value: &yamlmeta.MapProto{
278 Items: []*yamlmeta.MapItemProto{
279 &yamlmeta.MapItemProto{
280 Key: "array",
281 Value: &yamlmeta.ArrayProto{
282 Items: []*yamlmeta.ArrayItemProto{
283 &yamlmeta.ArrayItemProto{Value: 1, Position: filepos.NewPosition(3)},
284 &yamlmeta.ArrayItemProto{Value: 2, Position: filepos.NewPosition(4)},
285 &yamlmeta.ArrayItemProto{
286 Value: &yamlmeta.MapProto{
287 Items: []*yamlmeta.MapItemProto{
288 &yamlmeta.MapItemProto{
289 Key: "key",
290 Value: "value",
291 Position: filepos.NewPosition(5),
292 },
293 },
294 Position: filepos.NewPosition(5),
295 },
296 Position: filepos.NewPosition(5),
297 },
298 },
299 Position: filepos.NewPosition(2),
300 },
301 Position: filepos.NewPosition(2),
302 },
303 },
304 Position: filepos.NewPosition(1),
305 },
306 Position: filepos.NewPosition(1),
307 },
308 },
309 Position: filepos.NewUnknownPosition(),
310 })
311
312 printer := yamlmeta.NewPrinterWithOpts(nil, yamlmeta.PrinterOpts{ExcludeRefs: true})
313
314 parsedValStr := printer.PrintStr(parsedVal)
315 expectedValStr := printer.PrintStr(expectedVal)
316
317 assertEqual(t, parsedValStr, expectedValStr)
318}

Callers

nothing calls this directly

Calls 8

NewParserFunction · 0.92
NewDocumentSetFunction · 0.92
NewPositionFunction · 0.92
NewUnknownPositionFunction · 0.92
NewPrinterWithOptsFunction · 0.92
assertEqualFunction · 0.85
ParseBytesMethod · 0.80
PrintStrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…