This commit is contained in:
Mike Farah 2021-11-14 10:18:02 +11:00
parent d912d7d178
commit 63f54563ea
4 changed files with 20 additions and 15 deletions

View File

@ -118,7 +118,7 @@ var commentOperatorScenarios = []expressionScenario{
document: "# welcome!\n---\n# bob\na: cat # meow\n\n# have a great day",
expression: `headComment`,
expected: []string{
"D0, P[], (!!str)::|-\n welcome!\n bob\n",
"D0, P[], (!!str)::welcome!\nbob\n",
},
},
{

View File

@ -96,7 +96,7 @@ var equalsOperatorScenarios = []expressionScenario{
document: "{a: { b: {things: \"\"}, f: [1], g: [] }}",
expression: ".. | select(. == \"\")",
expected: []string{
"D0, P[a b things], (!!str)::\"\"\n",
"D0, P[a b things], (!!str)::\n",
},
},
{

View File

@ -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.
`
var docWithHeader = `
# here
var docWithHeader = `# here
a: apple
`
var nodeWithHeader = `
# here
var nodeWithHeader = `# here
a: apple
`
var docNoComments = `
b: banana
var docNoComments = `b: banana
`
var docWithFooter = `
a: apple
var docWithFooter = `a: apple
# footer
`
var nodeWithFooter = `
a: apple
var nodeWithFooter = `a: apple
# footer`
var document = `
a: &cat {name: cat}
var document = `a: &cat {name: cat}
b: {name: dog}
c:
<<: *cat

View File

@ -92,9 +92,20 @@ func testScenario(t *testing.T, s *expressionScenario) {
func resultsToString(results *list.List) []string {
var pretty []string = make([]string, 0)
for el := results.Front(); el != nil; el = el.Next() {
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
}