From 90ec05be543e615bf5d949fe5cb1a1bc28e13f61 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Tue, 12 Jan 2021 09:40:37 +1100 Subject: [PATCH] Fixed equals operator for top level node --- pkg/yqlib/operator_assign.go | 6 +----- pkg/yqlib/operator_equals.go | 9 ++++++--- pkg/yqlib/operator_equals_test.go | 9 +++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/yqlib/operator_assign.go b/pkg/yqlib/operator_assign.go index fe0048bb..49380daf 100644 --- a/pkg/yqlib/operator_assign.go +++ b/pkg/yqlib/operator_assign.go @@ -32,11 +32,7 @@ func assignUpdateOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNo candidate.UpdateFrom(rhsCandidate) } } - // // if there was nothing given, perhaps we are creating a new yaml doc - // if matchingNodes.Len() == 0 { - // log.Debug("started with nothing, returning LHS, %v", lhs.Len()) - // return lhs, nil - // } + return matchingNodes, nil } diff --git a/pkg/yqlib/operator_equals.go b/pkg/yqlib/operator_equals.go index ecacb2a9..accfee4a 100644 --- a/pkg/yqlib/operator_equals.go +++ b/pkg/yqlib/operator_equals.go @@ -12,10 +12,13 @@ func equalsOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *Pa func isEquals(d *dataTreeNavigator, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { value := false - if lhs.Node.Tag == "!!null" { - value = (rhs.Node.Tag == "!!null") + lhsNode := UnwrapDoc(lhs.Node) + rhsNode := UnwrapDoc(rhs.Node) + + if lhsNode.Tag == "!!null" { + value = (rhsNode.Tag == "!!null") } else { - value = matchKey(lhs.Node.Value, rhs.Node.Value) + value = matchKey(lhsNode.Value, rhsNode.Value) } log.Debugf("%v == %v ? %v", NodeToString(lhs), NodeToString(rhs), value) return createBooleanCandidate(lhs, value), nil diff --git a/pkg/yqlib/operator_equals_test.go b/pkg/yqlib/operator_equals_test.go index ce172503..2dfa20de 100644 --- a/pkg/yqlib/operator_equals_test.go +++ b/pkg/yqlib/operator_equals_test.go @@ -5,6 +5,15 @@ import ( ) var equalsOperatorScenarios = []expressionScenario{ + { + skipDoc: true, + document: "cat", + document2: "dog", + expression: "select(fi==0) == select(fi==1)", + expected: []string{ + "D0, P[], (!!bool)::false\n", + }, + }, { description: "Match string", document: `[cat,goat,dog]`,