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

Function TestParserDocSetComments

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

Source from the content-addressed store, hash-verified

497}
498
499func TestParserDocSetComments(t *testing.T) {
500 const data = `---
501# comment-first
502---
503---
504# comment-second
505`
506
507 parsedVal, err := yamlmeta.NewParser(yamlmeta.ParserOpts{WithoutComments: false}).ParseBytes([]byte(data), "")
508 if err != nil {
509 t.Fatalf("error: %s", err)
510 }
511
512 expectedVal := yamlmeta.NewDocumentSet(&yamlmeta.DocumentSetProto{
513 Items: []*yamlmeta.DocumentProto{
514 &yamlmeta.DocumentProto{
515 Position: filepos.NewPosition(1),
516 },
517 &yamlmeta.DocumentProto{
518 Comments: []*yamlmeta.CommentProto{
519 &yamlmeta.CommentProto{Data: " comment-first", Position: filepos.NewPosition(2)},
520 },
521 Position: filepos.NewPosition(3),
522 },
523 &yamlmeta.DocumentProto{
524 Position: filepos.NewPosition(4),
525 },
526 &yamlmeta.DocumentProto{
527 Comments: []*yamlmeta.CommentProto{
528 &yamlmeta.CommentProto{Data: " comment-second", Position: filepos.NewPosition(5)},
529 },
530 Position: filepos.NewUnknownPosition(),
531 },
532 },
533 Position: filepos.NewUnknownPosition(),
534 })
535
536 printer := yamlmeta.NewPrinterWithOpts(nil, yamlmeta.PrinterOpts{ExcludeRefs: true})
537
538 parsedValStr := printer.PrintStr(parsedVal)
539 expectedValStr := printer.PrintStr(expectedVal)
540
541 assertEqual(t, parsedValStr, expectedValStr)
542}
543
544func TestParserDocSetOnlyComments2(t *testing.T) {
545 const data = "---\n# comment-first\n"

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…