mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
Compare commits
4 Commits
b3ddce5527
...
008341b7a5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
008341b7a5 | ||
|
|
f654fbf459 | ||
|
|
5df71072f5 | ||
|
|
9883ebc313 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -46,7 +46,7 @@ jobs:
|
|||||||
./scripts/xcompile.sh
|
./scripts/xcompile.sh
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: build/*
|
files: build/*
|
||||||
draft: true
|
draft: true
|
||||||
|
|||||||
3
go.mod
3
go.mod
@ -30,5 +30,6 @@ require (
|
|||||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.21
|
go 1.21.0
|
||||||
|
|
||||||
toolchain go1.22.5
|
toolchain go1.22.5
|
||||||
|
|||||||
@ -11,6 +11,11 @@ func getExpressionParser() ExpressionParserInterface {
|
|||||||
return ExpressionParser
|
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) {
|
func TestParserNoMatchingCloseBracket(t *testing.T) {
|
||||||
_, err := getExpressionParser().ParseExpression(".cat | with(.;.bob")
|
_, err := getExpressionParser().ParseExpression(".cat | with(.;.bob")
|
||||||
test.AssertResultComplex(t, "bad expression - probably missing close bracket on WITH", err.Error())
|
test.AssertResultComplex(t, "bad expression - probably missing close bracket on WITH", err.Error())
|
||||||
|
|||||||
@ -126,7 +126,7 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
|
|||||||
if tokenIsOpType(currentToken, createMapOpType) {
|
if tokenIsOpType(currentToken, createMapOpType) {
|
||||||
log.Debugf("tokenIsOpType: createMapOpType")
|
log.Debugf("tokenIsOpType: createMapOpType")
|
||||||
// check the previous token is '[', means we are slice, but dont have a first number
|
// check the previous token is '[', means we are slice, but dont have a first number
|
||||||
if tokens[index-1].TokenType == traverseArrayCollect {
|
if index > 0 && tokens[index-1].TokenType == traverseArrayCollect {
|
||||||
log.Debugf("previous token is : traverseArrayOpType")
|
log.Debugf("previous token is : traverseArrayOpType")
|
||||||
// need to put the number 0 before this token, as that is implied
|
// need to put the number 0 before this token, as that is implied
|
||||||
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: createValueOperation(0, "0")})
|
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: createValueOperation(0, "0")})
|
||||||
|
|||||||
@ -14,6 +14,14 @@ var addOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[1 a], (!!int)::3\n",
|
"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,
|
skipDoc: true,
|
||||||
document: `a: key`,
|
document: `a: key`,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ func subtractOperator(d *dataTreeNavigator, context Context, expressionNode *Exp
|
|||||||
return crossFunction(d, context.ReadOnlyClone(), expressionNode, subtract, false)
|
return crossFunction(d, context.ReadOnlyClone(), expressionNode, subtract, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func subtractArray(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
func subtractArray(lhs *CandidateNode, rhs *CandidateNode) []*CandidateNode {
|
||||||
newLHSArray := make([]*CandidateNode, 0)
|
newLHSArray := make([]*CandidateNode, 0)
|
||||||
|
|
||||||
for lindex := 0; lindex < len(lhs.Content); lindex = lindex + 1 {
|
for lindex := 0; lindex < len(lhs.Content); lindex = lindex + 1 {
|
||||||
@ -37,9 +37,7 @@ func subtractArray(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, erro
|
|||||||
newLHSArray = append(newLHSArray, lhs.Content[lindex])
|
newLHSArray = append(newLHSArray, lhs.Content[lindex])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// removing children from LHS, parent hasn't changed
|
return newLHSArray
|
||||||
lhs.Content = newLHSArray
|
|
||||||
return lhs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
func subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
|
||||||
@ -56,7 +54,7 @@ func subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Ca
|
|||||||
if rhs.Kind != SequenceNode {
|
if rhs.Kind != SequenceNode {
|
||||||
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
|
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
|
||||||
}
|
}
|
||||||
return subtractArray(lhs, rhs)
|
target.Content = subtractArray(lhs, rhs)
|
||||||
case ScalarNode:
|
case ScalarNode:
|
||||||
if rhs.Kind != ScalarNode {
|
if rhs.Kind != ScalarNode {
|
||||||
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
|
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
|
||||||
|
|||||||
@ -13,6 +13,14 @@ var subtractOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::{}\n",
|
"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",
|
description: "Array subtraction",
|
||||||
expression: `[1,2] - [2,3]`,
|
expression: `[1,2] - [2,3]`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user