This commit is contained in:
Mike Farah 2021-07-19 19:58:47 +10:00
parent 3a6f73e836
commit 519cf1dcd7
3 changed files with 20 additions and 32 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}