mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Fixed to_entries[]
This commit is contained in:
parent
eff7d99e2b
commit
4cf123fed5
@ -298,7 +298,7 @@ func opTokenWithPrefs(opType *operationType, assignOpType *operationType, prefer
|
||||
if assignOpType != nil {
|
||||
assign = &Operation{OperationType: assignOpType, Value: assignOpType.Type, StringValue: value, Preferences: preferences}
|
||||
}
|
||||
return &token{TokenType: operationToken, Operation: op, AssignOperation: assign}, nil
|
||||
return &token{TokenType: operationToken, Operation: op, AssignOperation: assign, CheckForPostTraverse: op.OperationType.CheckForPostTraverse}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,10 +29,11 @@ func GetLogger() *logging.Logger {
|
||||
}
|
||||
|
||||
type operationType struct {
|
||||
Type string
|
||||
NumArgs uint // number of arguments to the op
|
||||
Precedence uint
|
||||
Handler operatorHandler
|
||||
Type string
|
||||
NumArgs uint // number of arguments to the op
|
||||
Precedence uint
|
||||
Handler operatorHandler
|
||||
CheckForPostTraverse bool
|
||||
}
|
||||
|
||||
var orOpType = &operationType{Type: "OR", NumArgs: 2, Precedence: 20, Handler: orOperator}
|
||||
@ -108,7 +109,7 @@ var containsOpType = &operationType{Type: "CONTAINS", NumArgs: 1, Precedence: 50
|
||||
var anyConditionOpType = &operationType{Type: "ANY_CONDITION", NumArgs: 1, Precedence: 50, Handler: anyOperator}
|
||||
var allConditionOpType = &operationType{Type: "ALL_CONDITION", NumArgs: 1, Precedence: 50, Handler: allOperator}
|
||||
|
||||
var toEntriesOpType = &operationType{Type: "TO_ENTRIES", NumArgs: 0, Precedence: 50, Handler: toEntriesOperator}
|
||||
var toEntriesOpType = &operationType{Type: "TO_ENTRIES", NumArgs: 0, Precedence: 52, Handler: toEntriesOperator, CheckForPostTraverse: true}
|
||||
var fromEntriesOpType = &operationType{Type: "FROM_ENTRIES", NumArgs: 0, Precedence: 50, Handler: fromEntriesOperator}
|
||||
var withEntriesOpType = &operationType{Type: "WITH_ENTRIES", NumArgs: 1, Precedence: 50, Handler: withEntriesOperator}
|
||||
|
||||
@ -152,7 +153,7 @@ var splitStringOpType = &operationType{Type: "SPLIT", NumArgs: 1, Precedence: 50
|
||||
var changeCaseOpType = &operationType{Type: "CHANGE_CASE", NumArgs: 0, Precedence: 50, Handler: changeCaseOperator}
|
||||
var trimOpType = &operationType{Type: "TRIM", NumArgs: 0, Precedence: 50, Handler: trimSpaceOperator}
|
||||
|
||||
var loadOpType = &operationType{Type: "LOAD", NumArgs: 1, Precedence: 50, Handler: loadYamlOperator}
|
||||
var loadOpType = &operationType{Type: "LOAD", NumArgs: 1, Precedence: 52, Handler: loadYamlOperator}
|
||||
|
||||
var keysOpType = &operationType{Type: "KEYS", NumArgs: 0, Precedence: 50, Handler: keysOperator}
|
||||
|
||||
|
@ -5,6 +5,16 @@ import (
|
||||
)
|
||||
|
||||
var entriesOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: "to_entries splat",
|
||||
skipDoc: true,
|
||||
document: `{a: 1, b: 2}`,
|
||||
expression: `to_entries[]`,
|
||||
expected: []string{
|
||||
"D0, P[0], (!!map)::key: a\nvalue: 1\n",
|
||||
"D0, P[1], (!!map)::key: b\nvalue: 2\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "to_entries, delete key",
|
||||
skipDoc: true,
|
||||
|
@ -13,6 +13,22 @@ var loadScenarios = []expressionScenario{
|
||||
"D0, P[], (!!null)::# comment\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Load and splat",
|
||||
expression: `load("../../examples/small.yaml")[]`,
|
||||
expected: []string{
|
||||
"D0, P[a], (!!str)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Load and traverse",
|
||||
expression: `load("../../examples/small.yaml").a`,
|
||||
expected: []string{
|
||||
"D0, P[a], (!!str)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Load file with a header comment into an array",
|
||||
|
Loading…
Reference in New Issue
Block a user