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
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab the first value
|
// find any truthy node
|
||||||
first := rhs.MatchingNodes.Front()
|
var errDecoding error
|
||||||
|
includeResult := false
|
||||||
|
|
||||||
if first != nil {
|
for resultEl := rhs.MatchingNodes.Front(); resultEl != nil; resultEl = resultEl.Next() {
|
||||||
result := first.Value.(*CandidateNode)
|
result := resultEl.Value.(*CandidateNode)
|
||||||
log.Debugf("result %v", NodeToString(result))
|
includeResult, errDecoding = isTruthy(result)
|
||||||
includeResult, errDecoding := isTruthy(result)
|
|
||||||
log.Debugf("isTruthy %v", includeResult)
|
log.Debugf("isTruthy %v", includeResult)
|
||||||
if errDecoding != nil {
|
if errDecoding != nil {
|
||||||
return Context{}, errDecoding
|
return Context{}, errDecoding
|
||||||
}
|
}
|
||||||
|
if includeResult {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if includeResult {
|
if includeResult {
|
||||||
results.PushBack(candidate)
|
results.PushBack(candidate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return context.ChildContext(results), nil
|
return context.ChildContext(results), nil
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var selectOperatorScenarios = []expressionScenario{
|
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",
|
description: "Select elements from array",
|
||||||
document: `[cat,goat,dog]`,
|
document: `[cat,goat,dog]`,
|
||||||
|
Loading…
Reference in New Issue
Block a user