mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Added printer test
This commit is contained in:
parent
088ec36acd
commit
2c062bc2a5
@ -17,13 +17,11 @@ type OperationType struct {
|
||||
}
|
||||
|
||||
// operators TODO:
|
||||
// - add print test, particular for streams with multilpe docs
|
||||
// (one that print doc1, then doc 3) in two calls
|
||||
// (one that prints doc1, then doc 3) in one call
|
||||
// - write in place
|
||||
// - get Kind
|
||||
// - get path operator (like doc index)
|
||||
// - get file index op (like doc index)
|
||||
// - get file name op (like doc index)
|
||||
// - write in place
|
||||
// - mergeAppend (merges and appends arrays)
|
||||
// - mergeEmpty (sets only if the document is empty, do I do that now?)
|
||||
// - updateTag - not recursive
|
||||
|
82
pkg/yqlib/printer_test.go
Normal file
82
pkg/yqlib/printer_test.go
Normal file
@ -0,0 +1,82 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v4/test"
|
||||
)
|
||||
|
||||
var multiDocSample = `a: banana
|
||||
---
|
||||
a: apple
|
||||
---
|
||||
a: coconut
|
||||
`
|
||||
|
||||
func TestPrinterMultipleDocsInSequence(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")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
el := inputs.Front()
|
||||
sample1 := nodeToMap(el.Value.(*CandidateNode))
|
||||
|
||||
el = el.Next()
|
||||
sample2 := nodeToMap(el.Value.(*CandidateNode))
|
||||
|
||||
el = el.Next()
|
||||
sample3 := nodeToMap(el.Value.(*CandidateNode))
|
||||
|
||||
printer.PrintResults(sample1)
|
||||
printer.PrintResults(sample2)
|
||||
printer.PrintResults(sample3)
|
||||
|
||||
writer.Flush()
|
||||
test.AssertResult(t, multiDocSample, output.String())
|
||||
|
||||
}
|
||||
|
||||
func TestPrinterMultipleDocsInSinglePrint(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")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
printer.PrintResults(inputs)
|
||||
|
||||
writer.Flush()
|
||||
test.AssertResult(t, multiDocSample, output.String())
|
||||
}
|
||||
|
||||
func TestPrinterMultipleDocsJson(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
var writer = bufio.NewWriter(&output)
|
||||
printer := NewPrinter(writer, true, true, false, 0, false)
|
||||
|
||||
inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
printer.PrintResults(inputs)
|
||||
|
||||
expected := `{"a":"banana"}
|
||||
{"a":"apple"}
|
||||
{"a":"coconut"}
|
||||
`
|
||||
|
||||
writer.Flush()
|
||||
test.AssertResult(t, expected, output.String())
|
||||
}
|
Loading…
Reference in New Issue
Block a user