2020-12-17 03:02:54 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mikefarah/yq/v4/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathTreeNoArgsForTwoArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression("=")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, "'=' expects 2 args but there is 0", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathTreeOneLhsArgsForTwoArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression(".a =")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathTreeOneRhsArgsForTwoArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression("= .a")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, "'=' expects 2 args but there is 1", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathTreeTwoArgsForTwoArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression(".a = .b")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, nil, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathTreeNoArgsForOneArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression("explode")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, "'explode' expects 1 arg but received none", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPathTreeOneArgForOneArgOp(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression("explode(.)")
|
2020-12-17 03:02:54 +00:00
|
|
|
test.AssertResultComplex(t, nil, err)
|
|
|
|
}
|
2020-12-17 03:19:46 +00:00
|
|
|
|
|
|
|
func TestPathTreeExtraArgs(t *testing.T) {
|
2021-01-12 23:18:53 +00:00
|
|
|
_, err := NewExpressionParser().ParseExpression("sortKeys(.) explode(.)")
|
2020-12-17 03:19:46 +00:00
|
|
|
test.AssertResultComplex(t, "expected end of expression but found 'explode', please check expression syntax", err.Error())
|
|
|
|
}
|