yq/pkg/yqlib/all_at_once_evaluator_test.go

42 lines
807 B
Go
Raw Normal View History

2021-01-12 19:29:05 +00:00
package yqlib
import (
"testing"
"github.com/mikefarah/yq/v4/test"
)
var evaluateNodesScenario = []expressionScenario{
{
document: `a: hello`,
expression: `.a`,
expected: []string{
"D0, P[a], (!!str)::hello\n",
},
},
{
document: `a: hello`,
expression: `.`,
expected: []string{
"D0, P[], (doc)::a: hello\n",
},
},
{
document: `- a: "yes"`,
expression: `.[] | has("a")`,
expected: []string{
"D0, P[0], (!!bool)::true\n",
},
},
}
2021-01-12 22:35:57 +00:00
func TestAllAtOnceEvaluateNodes(t *testing.T) {
2022-02-01 03:47:51 +00:00
InitExpressionParser()
2021-01-12 22:35:57 +00:00
var evaluator = NewAllAtOnceEvaluator()
2021-01-12 19:29:05 +00:00
for _, tt := range evaluateNodesScenario {
node := test.ParseData(tt.document)
2021-01-12 22:35:57 +00:00
list, _ := evaluator.EvaluateNodes(tt.expression, &node)
2021-11-13 23:51:18 +00:00
test.AssertResultComplex(t, tt.expected, resultsToString(t, list))
2021-01-12 19:29:05 +00:00
}
}