mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-14 12:35:35 +00:00
Handle scalars in csv, xml files
This commit is contained in:
parent
1b0a62d08d
commit
8d516ce535
@ -126,6 +126,14 @@ var csvScenarios = []formatScenario{
|
|||||||
expected: expectedYamlFromCSV,
|
expected: expectedYamlFromCSV,
|
||||||
scenarioType: "decode-csv-object",
|
scenarioType: "decode-csv-object",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Scalar roundtrip",
|
||||||
|
skipDoc: true,
|
||||||
|
input: "mike\ncat",
|
||||||
|
expression: ".[0].mike",
|
||||||
|
expected: "cat\n",
|
||||||
|
scenarioType: "roundtrip-csv",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Parse TSV into an array of objects",
|
description: "Parse TSV into an array of objects",
|
||||||
subdescription: "First row is assumed to be the header row.",
|
subdescription: "First row is assumed to be the header row.",
|
||||||
|
@ -103,6 +103,10 @@ func (e *csvEncoder) encodeObjects(csvWriter *csv.Writer, content []*yaml.Node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *csvEncoder) Encode(writer io.Writer, originalNode *yaml.Node) error {
|
func (e *csvEncoder) Encode(writer io.Writer, originalNode *yaml.Node) error {
|
||||||
|
if originalNode.Kind == yaml.ScalarNode {
|
||||||
|
return writeString(writer, originalNode.Value+"\n")
|
||||||
|
}
|
||||||
|
|
||||||
csvWriter := csv.NewWriter(writer)
|
csvWriter := csv.NewWriter(writer)
|
||||||
csvWriter.Comma = e.separator
|
csvWriter.Comma = e.separator
|
||||||
|
|
||||||
|
@ -301,6 +301,14 @@ var xmlScenarios = []formatScenario{
|
|||||||
expected: expectedXmlProcInstAndHeadComment,
|
expected: expectedXmlProcInstAndHeadComment,
|
||||||
scenarioType: "encode",
|
scenarioType: "encode",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Scalar roundtrip",
|
||||||
|
skipDoc: true,
|
||||||
|
input: "<mike>cat</mike>",
|
||||||
|
expression: ".mike",
|
||||||
|
expected: "cat",
|
||||||
|
scenarioType: "roundtrip",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "ProcInst with head comment round trip",
|
description: "ProcInst with head comment round trip",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user