diff --git a/pkg/yqlib/operator_comments_test.go b/pkg/yqlib/operator_comments_test.go index f951ed0b..bd724a8f 100644 --- a/pkg/yqlib/operator_comments_test.go +++ b/pkg/yqlib/operator_comments_test.go @@ -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", }, }, { diff --git a/pkg/yqlib/operator_equals_test.go b/pkg/yqlib/operator_equals_test.go index 360e7e99..1064ebd3 100644 --- a/pkg/yqlib/operator_equals_test.go +++ b/pkg/yqlib/operator_equals_test.go @@ -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", }, }, { diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index 39bb83a9..7e1f38f2 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -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 diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index e784f319..10c9260d 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -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 }