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) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|