mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
adding pipe
This commit is contained in:
parent
afffb2c3ba
commit
449fb8952c
@ -357,7 +357,7 @@ func TestDataTreeNavigatorCountMultipleMatchesInside(t *testing.T) {
|
||||
b: dally
|
||||
c: [3,4,5]`)
|
||||
|
||||
path, errPath := treeCreator.ParsePath("f(count(a or c))")
|
||||
path, errPath := treeCreator.ParsePath("f | count(a or c)")
|
||||
if errPath != nil {
|
||||
t.Error(errPath)
|
||||
}
|
||||
@ -384,7 +384,7 @@ func TestDataTreeNavigatorCollectMultipleMatchesInside(t *testing.T) {
|
||||
b: dally
|
||||
c: [3,4,5]`)
|
||||
|
||||
path, errPath := treeCreator.ParsePath("f(collect(a or c))")
|
||||
path, errPath := treeCreator.ParsePath("f | collect(a or c)")
|
||||
if errPath != nil {
|
||||
t.Error(errPath)
|
||||
}
|
||||
|
@ -30,15 +30,15 @@ type OperationType struct {
|
||||
}
|
||||
|
||||
var None = &OperationType{Type: "NONE", NumArgs: 0, Precedence: 0}
|
||||
var Traverse = &OperationType{Type: "TRAVERSE", NumArgs: 2, Precedence: 40, Handler: TraverseOperator}
|
||||
var Traverse = &OperationType{Type: "TRAVERSE", NumArgs: 2, Precedence: 35, Handler: TraverseOperator}
|
||||
var Or = &OperationType{Type: "OR", NumArgs: 2, Precedence: 10, Handler: UnionOperator}
|
||||
var And = &OperationType{Type: "AND", NumArgs: 2, Precedence: 20, Handler: IntersectionOperator}
|
||||
var Equals = &OperationType{Type: "EQUALS", NumArgs: 2, Precedence: 30, Handler: EqualsOperator}
|
||||
var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 35, Handler: AssignOperator}
|
||||
var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: AssignOperator}
|
||||
var DeleteChild = &OperationType{Type: "DELETE", NumArgs: 2, Precedence: 30, Handler: DeleteChildOperator}
|
||||
|
||||
var Count = &OperationType{Type: "COUNT", NumArgs: 1, Precedence: 35, Handler: CountOperator}
|
||||
var Collect = &OperationType{Type: "COLLECT", NumArgs: 1, Precedence: 35, Handler: CollectOperator}
|
||||
var Count = &OperationType{Type: "COUNT", NumArgs: 1, Precedence: 40, Handler: CountOperator}
|
||||
var Collect = &OperationType{Type: "COLLECT", NumArgs: 1, Precedence: 40, Handler: CollectOperator}
|
||||
|
||||
// var Exists = &OperationType{Type: "Length", NumArgs: 2, Precedence: 35}
|
||||
// filters matches if they have the existing path
|
||||
|
@ -25,6 +25,26 @@ func testExpression(expression string) (string, error) {
|
||||
return formatted, nil
|
||||
}
|
||||
|
||||
func TestPostFixTraverseBar(t *testing.T) {
|
||||
var infix = "animals | collect(.)"
|
||||
var expectedOutput = `PathKey - 'animals'
|
||||
--------
|
||||
SELF
|
||||
--------
|
||||
Operation - COLLECT
|
||||
--------
|
||||
Operation - TRAVERSE
|
||||
--------
|
||||
`
|
||||
|
||||
actual, err := testExpression(infix)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
test.AssertResultComplex(t, expectedOutput, actual)
|
||||
}
|
||||
|
||||
func TestPostFixArrayEquals(t *testing.T) {
|
||||
var infix = "animals(.== cat)"
|
||||
var expectedOutput = `PathKey - 'animals'
|
||||
|
@ -94,8 +94,9 @@ func initLexer() (*lex.Lexer, error) {
|
||||
lexer.Add([]byte("( |\t|\n|\r)+"), skip)
|
||||
|
||||
lexer.Add([]byte(`"[^ "]+"`), pathToken(true))
|
||||
lexer.Add([]byte(`[^ \.\[\(\)=]+`), pathToken(false))
|
||||
lexer.Add([]byte(`[^ \|\.\[\(\)=]+`), pathToken(false))
|
||||
|
||||
lexer.Add([]byte(`\|`), opToken(Traverse, false))
|
||||
lexer.Add([]byte(`\.`), opToken(Traverse, false))
|
||||
err := lexer.Compile()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user