mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
wip
This commit is contained in:
parent
d912d7d178
commit
63f54563ea
@ -118,7 +118,7 @@ var commentOperatorScenarios = []expressionScenario{
|
|||||||
document: "# welcome!\n---\n# bob\na: cat # meow\n\n# have a great day",
|
document: "# welcome!\n---\n# bob\na: cat # meow\n\n# have a great day",
|
||||||
expression: `headComment`,
|
expression: `headComment`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!str)::|-\n welcome!\n bob\n",
|
"D0, P[], (!!str)::welcome!\nbob\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -96,7 +96,7 @@ var equalsOperatorScenarios = []expressionScenario{
|
|||||||
document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
|
document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
|
||||||
expression: ".. | select(. == \"\")",
|
expression: ".. | select(. == \"\")",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[a b things], (!!str)::\"\"\n",
|
"D0, P[a b things], (!!str)::\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -35,33 +35,27 @@ We then need to update the first array. We will use the relative update (|=) bec
|
|||||||
We set the current element of the first array as $cur. Now we multiply (merge) $cur with the matching entry in $two, by passing $two through a select filter.
|
We set the current element of the first array as $cur. Now we multiply (merge) $cur with the matching entry in $two, by passing $two through a select filter.
|
||||||
`
|
`
|
||||||
|
|
||||||
var docWithHeader = `
|
var docWithHeader = `# here
|
||||||
# here
|
|
||||||
|
|
||||||
a: apple
|
a: apple
|
||||||
`
|
`
|
||||||
|
|
||||||
var nodeWithHeader = `
|
var nodeWithHeader = `# here
|
||||||
# here
|
|
||||||
a: apple
|
a: apple
|
||||||
`
|
`
|
||||||
|
|
||||||
var docNoComments = `
|
var docNoComments = `b: banana
|
||||||
b: banana
|
|
||||||
`
|
`
|
||||||
|
|
||||||
var docWithFooter = `
|
var docWithFooter = `a: apple
|
||||||
a: apple
|
|
||||||
|
|
||||||
# footer
|
# footer
|
||||||
`
|
`
|
||||||
|
|
||||||
var nodeWithFooter = `
|
var nodeWithFooter = `a: apple
|
||||||
a: apple
|
|
||||||
# footer`
|
# footer`
|
||||||
|
|
||||||
var document = `
|
var document = `a: &cat {name: cat}
|
||||||
a: &cat {name: cat}
|
|
||||||
b: {name: dog}
|
b: {name: dog}
|
||||||
c:
|
c:
|
||||||
<<: *cat
|
<<: *cat
|
||||||
|
@ -92,9 +92,20 @@ func testScenario(t *testing.T, s *expressionScenario) {
|
|||||||
|
|
||||||
func resultsToString(results *list.List) []string {
|
func resultsToString(results *list.List) []string {
|
||||||
var pretty []string = make([]string, 0)
|
var pretty []string = make([]string, 0)
|
||||||
|
|
||||||
for el := results.Front(); el != nil; el = el.Next() {
|
for el := results.Front(); el != nil; el = el.Next() {
|
||||||
n := el.Value.(*CandidateNode)
|
n := el.Value.(*CandidateNode)
|
||||||
pretty = append(pretty, NodeToString(n))
|
var valueBuffer bytes.Buffer
|
||||||
|
printer := NewPrinterWithSingleWriter(bufio.NewWriter(&valueBuffer), YamlOutputFormat, true, false, 4, true)
|
||||||
|
printer.PrintResults(n.AsList())
|
||||||
|
tag := n.Node.Tag
|
||||||
|
if n.Node.Kind == yaml.DocumentNode {
|
||||||
|
tag = "doc"
|
||||||
|
} else if n.Node.Kind == yaml.AliasNode {
|
||||||
|
tag = "alias"
|
||||||
|
}
|
||||||
|
output := fmt.Sprintf(`D%v, P%v, (%v)::%v`, n.Document, n.Path, tag, valueBuffer.String())
|
||||||
|
pretty = append(pretty, output)
|
||||||
}
|
}
|
||||||
return pretty
|
return pretty
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user