yq/pkg/yqlib/all_at_once_evaluator_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2021-01-12 19:29:05 +00:00
package yqlib
import (
"bufio"
"strings"
2021-01-12 19:29:05 +00:00
"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[], (!!map)::a: hello\n",
2021-01-12 19:29:05 +00:00
},
},
{
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()
// logging.SetLevel(logging.DEBUG, "")
2021-01-12 19:29:05 +00:00
for _, tt := range evaluateNodesScenario {
decoder := NewYamlDecoder(NewDefaultYamlPreferences())
reader := bufio.NewReader(strings.NewReader(tt.document))
err := decoder.Init(reader)
if err != nil {
t.Error(err)
return
}
candidateNode, errorReading := decoder.Decode()
if errorReading != nil {
t.Error(errorReading)
return
}
list, _ := evaluator.EvaluateNodes(tt.expression, candidateNode)
2021-11-13 23:51:18 +00:00
test.AssertResultComplex(t, tt.expected, resultsToString(t, list))
2021-01-12 19:29:05 +00:00
}
}