mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 11:55:38 +00:00
Added printer tests
This commit is contained in:
parent
519cf1dcd7
commit
dafa114e65
@ -17,20 +17,22 @@ a: apple
|
|||||||
a: coconut
|
a: coconut
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var multiDocSampleLeadingExpected = `# go cats
|
||||||
|
---
|
||||||
|
a: banana
|
||||||
|
---
|
||||||
|
a: apple
|
||||||
|
---
|
||||||
|
# cool
|
||||||
|
a: coconut
|
||||||
|
`
|
||||||
|
|
||||||
func nodeToList(candidate *CandidateNode) *list.List {
|
func nodeToList(candidate *CandidateNode) *list.List {
|
||||||
elMap := list.New()
|
elMap := list.New()
|
||||||
elMap.PushBack(candidate)
|
elMap.PushBack(candidate)
|
||||||
return elMap
|
return elMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrinterWithLeadingContentEvalStyle(t *testing.T) {
|
|
||||||
test.AssertResult(t, "todo", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrinterWithLeadingContentEvalAllStyle(t *testing.T) {
|
|
||||||
test.AssertResult(t, "todo", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrinterMultipleDocsInSequence(t *testing.T) {
|
func TestPrinterMultipleDocsInSequence(t *testing.T) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
var writer = bufio.NewWriter(&output)
|
var writer = bufio.NewWriter(&output)
|
||||||
@ -69,6 +71,45 @@ func TestPrinterMultipleDocsInSequence(t *testing.T) {
|
|||||||
test.AssertResult(t, multiDocSample, output.String())
|
test.AssertResult(t, multiDocSample, output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrinterMultipleDocsInSequenceWithLeadingContent(t *testing.T) {
|
||||||
|
var output bytes.Buffer
|
||||||
|
var writer = bufio.NewWriter(&output)
|
||||||
|
printer := NewPrinter(writer, false, true, false, 2, true)
|
||||||
|
|
||||||
|
inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
el := inputs.Front()
|
||||||
|
sample1 := nodeToList(el.Value.(*CandidateNode))
|
||||||
|
|
||||||
|
el = el.Next()
|
||||||
|
sample2 := nodeToList(el.Value.(*CandidateNode))
|
||||||
|
|
||||||
|
el = el.Next()
|
||||||
|
sample3 := nodeToList(el.Value.(*CandidateNode))
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample1, "# go cats\n---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample2, "---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample3, "---\n# cool\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
|
||||||
|
test.AssertResult(t, multiDocSampleLeadingExpected, output.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrinterMultipleFilesInSequence(t *testing.T) {
|
func TestPrinterMultipleFilesInSequence(t *testing.T) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
var writer = bufio.NewWriter(&output)
|
var writer = bufio.NewWriter(&output)
|
||||||
@ -116,6 +157,53 @@ func TestPrinterMultipleFilesInSequence(t *testing.T) {
|
|||||||
test.AssertResult(t, multiDocSample, output.String())
|
test.AssertResult(t, multiDocSample, output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrinterMultipleFilesInSequenceWithLeadingContent(t *testing.T) {
|
||||||
|
var output bytes.Buffer
|
||||||
|
var writer = bufio.NewWriter(&output)
|
||||||
|
printer := NewPrinter(writer, false, true, false, 2, true)
|
||||||
|
|
||||||
|
inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
el := inputs.Front()
|
||||||
|
elNode := el.Value.(*CandidateNode)
|
||||||
|
elNode.Document = 0
|
||||||
|
elNode.FileIndex = 0
|
||||||
|
sample1 := nodeToList(elNode)
|
||||||
|
|
||||||
|
el = el.Next()
|
||||||
|
elNode = el.Value.(*CandidateNode)
|
||||||
|
elNode.Document = 0
|
||||||
|
elNode.FileIndex = 1
|
||||||
|
sample2 := nodeToList(elNode)
|
||||||
|
|
||||||
|
el = el.Next()
|
||||||
|
elNode = el.Value.(*CandidateNode)
|
||||||
|
elNode.Document = 0
|
||||||
|
elNode.FileIndex = 2
|
||||||
|
sample3 := nodeToList(elNode)
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample1, "# go cats\n---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample2, "---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(sample3, "---\n# cool\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
test.AssertResult(t, multiDocSampleLeadingExpected, output.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrinterMultipleDocsInSinglePrint(t *testing.T) {
|
func TestPrinterMultipleDocsInSinglePrint(t *testing.T) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
var writer = bufio.NewWriter(&output)
|
var writer = bufio.NewWriter(&output)
|
||||||
@ -135,6 +223,59 @@ func TestPrinterMultipleDocsInSinglePrint(t *testing.T) {
|
|||||||
test.AssertResult(t, multiDocSample, output.String())
|
test.AssertResult(t, multiDocSample, output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrinterMultipleDocsInSinglePrintWithLeadingDoc(t *testing.T) {
|
||||||
|
var output bytes.Buffer
|
||||||
|
var writer = bufio.NewWriter(&output)
|
||||||
|
printer := NewPrinter(writer, false, true, false, 2, true)
|
||||||
|
|
||||||
|
inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(inputs, "# go cats\n---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
expected := `# go cats
|
||||||
|
---
|
||||||
|
a: banana
|
||||||
|
---
|
||||||
|
a: apple
|
||||||
|
---
|
||||||
|
a: coconut
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expected, output.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrinterMultipleDocsInSinglePrintWithLeadingDocTrailing(t *testing.T) {
|
||||||
|
var output bytes.Buffer
|
||||||
|
var writer = bufio.NewWriter(&output)
|
||||||
|
printer := NewPrinter(writer, false, true, false, 2, true)
|
||||||
|
|
||||||
|
inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = printer.PrintResults(inputs, "---\n")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
expected := `---
|
||||||
|
a: banana
|
||||||
|
---
|
||||||
|
a: apple
|
||||||
|
---
|
||||||
|
a: coconut
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expected, output.String())
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrinterMultipleDocsJson(t *testing.T) {
|
func TestPrinterMultipleDocsJson(t *testing.T) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
var writer = bufio.NewWriter(&output)
|
var writer = bufio.NewWriter(&output)
|
||||||
|
Loading…
Reference in New Issue
Block a user