mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-29 02:25:41 +00:00
40 lines
729 B
Go
40 lines
729 B
Go
|
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",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func TestEvaluateNodesScenarios(t *testing.T) {
|
||
|
for _, tt := range evaluateNodesScenario {
|
||
|
node := test.ParseData(tt.document)
|
||
|
list, _ := EvaluateNodes(tt.expression, &node)
|
||
|
test.AssertResultComplex(t, tt.expected, resultsToString(list))
|
||
|
}
|
||
|
}
|