From feda9f044dea60b0b95cd1d503132e3fd545957d Mon Sep 17 00:00:00 2001 From: Mikhail Katychev Date: Tue, 12 Jan 2021 13:29:05 -0600 Subject: [PATCH] added lib_test.go --- pkg/yqlib/lib_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 pkg/yqlib/lib_test.go diff --git a/pkg/yqlib/lib_test.go b/pkg/yqlib/lib_test.go new file mode 100644 index 00000000..b62ba39b --- /dev/null +++ b/pkg/yqlib/lib_test.go @@ -0,0 +1,39 @@ +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)) + } +}