mirror of
https://github.com/mikefarah/yq.git
synced 2025-03-10 11:15:36 +00:00
Fixed select bug (#958)
This commit is contained in:
parent
e87808683a
commit
839f795710
@ -17,22 +17,25 @@ func selectOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
// grab the first value
|
||||
first := rhs.MatchingNodes.Front()
|
||||
// find any truthy node
|
||||
var errDecoding error
|
||||
includeResult := false
|
||||
|
||||
if first != nil {
|
||||
result := first.Value.(*CandidateNode)
|
||||
log.Debugf("result %v", NodeToString(result))
|
||||
includeResult, errDecoding := isTruthy(result)
|
||||
for resultEl := rhs.MatchingNodes.Front(); resultEl != nil; resultEl = resultEl.Next() {
|
||||
result := resultEl.Value.(*CandidateNode)
|
||||
includeResult, errDecoding = isTruthy(result)
|
||||
log.Debugf("isTruthy %v", includeResult)
|
||||
if errDecoding != nil {
|
||||
return Context{}, errDecoding
|
||||
}
|
||||
if includeResult {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if includeResult {
|
||||
results.PushBack(candidate)
|
||||
}
|
||||
}
|
||||
}
|
||||
return context.ChildContext(results), nil
|
||||
}
|
||||
|
@ -5,6 +5,28 @@ import (
|
||||
)
|
||||
|
||||
var selectOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `cat`,
|
||||
expression: `select(false, true)`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `cat`,
|
||||
expression: `select(true, false)`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `cat`,
|
||||
expression: `select(false)`,
|
||||
expected: []string{},
|
||||
},
|
||||
{
|
||||
description: "Select elements from array",
|
||||
document: `[cat,goat,dog]`,
|
||||
|
Loading…
Reference in New Issue
Block a user