1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Fixed nil RHS bug in alternative operator #838

This commit is contained in:
Mike Farah 2021-05-28 16:59:02 +10:00
parent 38b9856f50
commit f1f75683c1
4 changed files with 27 additions and 2 deletions

View File

@ -5,6 +5,12 @@ import (
) )
var alternativeOperatorScenarios = []expressionScenario{ var alternativeOperatorScenarios = []expressionScenario{
{
skipDoc: true,
expression: `.b // .c`,
document: `a: bridge`,
expected: []string{},
},
{ {
skipDoc: true, skipDoc: true,
expression: `(.b // "hello") as $x`, expression: `(.b // "hello") as $x`,

View File

@ -12,6 +12,14 @@ var booleanOperatorScenarios = []expressionScenario{
"D0, P[], (!!bool)::true\n", "D0, P[], (!!bool)::true\n",
}, },
}, },
{
skipDoc: true,
document: "b: hi",
expression: `.a or .c`,
expected: []string{
"D0, P[], (!!bool)::false\n",
},
},
{ {
skipDoc: true, skipDoc: true,
document: "b: hi", document: "b: hi",

View File

@ -5,6 +5,13 @@ import (
) )
var equalsOperatorScenarios = []expressionScenario{ var equalsOperatorScenarios = []expressionScenario{
{
skipDoc: true,
expression: ".a == .b",
expected: []string{
"D0, P[], (!!bool)::true\n",
},
},
{ {
skipDoc: true, skipDoc: true,
document: "cat", document: "cat",

View File

@ -31,7 +31,9 @@ func resultsForRhs(d *dataTreeNavigator, context Context, lhsCandidate *Candidat
if err != nil { if err != nil {
return err return err
} }
results.PushBack(resultCandidate) if resultCandidate != nil {
results.PushBack(resultCandidate)
}
return nil return nil
} }
@ -42,7 +44,9 @@ func resultsForRhs(d *dataTreeNavigator, context Context, lhsCandidate *Candidat
if err != nil { if err != nil {
return err return err
} }
results.PushBack(resultCandidate) if resultCandidate != nil {
results.PushBack(resultCandidate)
}
} }
return nil return nil
} }