From 519cf1dcd7ac11aed1aacb4d9b8476513dd439de Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 19 Jul 2021 19:58:47 +1000 Subject: [PATCH] wip --- pkg/yqlib/operators_test.go | 2 +- pkg/yqlib/printer.go | 8 +++++-- pkg/yqlib/printer_test.go | 42 ++++++++++++------------------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index c5fe1fe4..4299fba9 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -114,7 +114,7 @@ func formatYaml(yaml string, filename string) string { panic(err) } streamEvaluator := NewStreamEvaluator() - _, err = streamEvaluator.Evaluate(filename, strings.NewReader(yaml), node, printer) + _, err = streamEvaluator.Evaluate(filename, strings.NewReader(yaml), node, printer, "") if err != nil { panic(err) } diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index 7f3a1a05..2307004e 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -101,7 +101,9 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List, leadingContent s defer p.safelyFlush(bufferedWriter) if matchingNodes.Len() == 0 { - p.writeString(bufferedWriter, leadingContent) + if err := p.writeString(bufferedWriter, leadingContent); err != nil { + return err + } log.Debug("no matching results, nothing to print") return nil } @@ -127,7 +129,9 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List, leadingContent s if !printedLead { // we want to print this after the seperator logic - p.writeString(bufferedWriter, leadingContent) + if err := p.writeString(bufferedWriter, leadingContent); err != nil { + return err + } printedLead = true } diff --git a/pkg/yqlib/printer_test.go b/pkg/yqlib/printer_test.go index fddf6485..23ce183f 100644 --- a/pkg/yqlib/printer_test.go +++ b/pkg/yqlib/printer_test.go @@ -17,34 +17,18 @@ a: apple a: coconut ` -var leadingSeperatorSample = `--- -a: good doc -` - func nodeToList(candidate *CandidateNode) *list.List { elMap := list.New() elMap.PushBack(candidate) return elMap } -func TestPrinterWithLeadingSeperator(t *testing.T) { - var output bytes.Buffer - var writer = bufio.NewWriter(&output) - printer := NewPrinter(writer, false, true, false, 2, true) +func TestPrinterWithLeadingContentEvalStyle(t *testing.T) { + test.AssertResult(t, "todo", "") +} - inputs, err := readDocuments(strings.NewReader(leadingSeperatorSample), "sample.yml", 0) - if err != nil { - panic(err) - } - printer.SetPrintLeadingSeperator(true) - - err = printer.PrintResults(inputs) - if err != nil { - panic(err) - } - - writer.Flush() - test.AssertResult(t, leadingSeperatorSample, output.String()) +func TestPrinterWithLeadingContentEvalAllStyle(t *testing.T) { + test.AssertResult(t, "todo", "") } func TestPrinterMultipleDocsInSequence(t *testing.T) { @@ -66,17 +50,17 @@ func TestPrinterMultipleDocsInSequence(t *testing.T) { el = el.Next() sample3 := nodeToList(el.Value.(*CandidateNode)) - err = printer.PrintResults(sample1) + err = printer.PrintResults(sample1, "") if err != nil { panic(err) } - err = printer.PrintResults(sample2) + err = printer.PrintResults(sample2, "") if err != nil { panic(err) } - err = printer.PrintResults(sample3) + err = printer.PrintResults(sample3, "") if err != nil { panic(err) } @@ -113,17 +97,17 @@ func TestPrinterMultipleFilesInSequence(t *testing.T) { elNode.FileIndex = 2 sample3 := nodeToList(elNode) - err = printer.PrintResults(sample1) + err = printer.PrintResults(sample1, "") if err != nil { panic(err) } - err = printer.PrintResults(sample2) + err = printer.PrintResults(sample2, "") if err != nil { panic(err) } - err = printer.PrintResults(sample3) + err = printer.PrintResults(sample3, "") if err != nil { panic(err) } @@ -142,7 +126,7 @@ func TestPrinterMultipleDocsInSinglePrint(t *testing.T) { panic(err) } - err = printer.PrintResults(inputs) + err = printer.PrintResults(inputs, "") if err != nil { panic(err) } @@ -163,7 +147,7 @@ func TestPrinterMultipleDocsJson(t *testing.T) { panic(err) } - err = printer.PrintResults(inputs) + err = printer.PrintResults(inputs, "") if err != nil { panic(err) }