Compare commits

..

No commits in common. "f654fbf4598c06e18b11a4bd504eba16459be80c" and "cc7738bb8d560850519b1f64a2d23f41382e8c2c" have entirely different histories.

6 changed files with 7 additions and 27 deletions

3
go.mod
View File

@ -30,6 +30,5 @@ require (
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
)
go 1.21.0
go 1.21
toolchain go1.22.5

View File

@ -11,11 +11,6 @@ func getExpressionParser() ExpressionParserInterface {
return ExpressionParser
}
func TestParserCreateMapColonOnItsOwn(t *testing.T) {
_, err := getExpressionParser().ParseExpression(":")
test.AssertResultComplex(t, "':' expects 2 args but there is 0", err.Error())
}
func TestParserNoMatchingCloseBracket(t *testing.T) {
_, err := getExpressionParser().ParseExpression(".cat | with(.;.bob")
test.AssertResultComplex(t, "bad expression - probably missing close bracket on WITH", err.Error())

View File

@ -126,7 +126,7 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
if tokenIsOpType(currentToken, createMapOpType) {
log.Debugf("tokenIsOpType: createMapOpType")
// check the previous token is '[', means we are slice, but dont have a first number
if index > 0 && tokens[index-1].TokenType == traverseArrayCollect {
if tokens[index-1].TokenType == traverseArrayCollect {
log.Debugf("previous token is : traverseArrayOpType")
// need to put the number 0 before this token, as that is implied
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: createValueOperation(0, "0")})

View File

@ -14,14 +14,6 @@ var addOperatorScenarios = []expressionScenario{
"D0, P[1 a], (!!int)::3\n",
},
},
{
skipDoc: true,
description: "add sequence creates a new sequence",
expression: `["a"] as $f | {0:$f + ["b"], 1:$f}`,
expected: []string{
"D0, P[], (!!map)::0:\n - a\n - b\n1:\n - a\n",
},
},
{
skipDoc: true,
document: `a: key`,

View File

@ -23,7 +23,7 @@ func subtractOperator(d *dataTreeNavigator, context Context, expressionNode *Exp
return crossFunction(d, context.ReadOnlyClone(), expressionNode, subtract, false)
}
func subtractArray(lhs *CandidateNode, rhs *CandidateNode) []*CandidateNode {
func subtractArray(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
newLHSArray := make([]*CandidateNode, 0)
for lindex := 0; lindex < len(lhs.Content); lindex = lindex + 1 {
@ -37,7 +37,9 @@ func subtractArray(lhs *CandidateNode, rhs *CandidateNode) []*CandidateNode {
newLHSArray = append(newLHSArray, lhs.Content[lindex])
}
}
return newLHSArray
// removing children from LHS, parent hasn't changed
lhs.Content = newLHSArray
return lhs, nil
}
func subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
@ -54,7 +56,7 @@ func subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Ca
if rhs.Kind != SequenceNode {
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
}
target.Content = subtractArray(lhs, rhs)
return subtractArray(lhs, rhs)
case ScalarNode:
if rhs.Kind != ScalarNode {
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)

View File

@ -13,14 +13,6 @@ var subtractOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::{}\n",
},
},
{
skipDoc: true,
description: "subtract sequence creates a new sequence",
expression: `["a", "b"] as $f | {0:$f - ["a"], 1:$f}`,
expected: []string{
"D0, P[], (!!map)::0:\n - b\n1:\n - a\n - b\n",
},
},
{
description: "Array subtraction",
expression: `[1,2] - [2,3]`,