mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Adding a EvaluateAll function to StringEvaluator #1966
This commit is contained in:
@@ -6,6 +6,20 @@ import (
|
||||
"github.com/mikefarah/yq/v4/test"
|
||||
)
|
||||
|
||||
func TestStringEvaluator_MultipleDocumentMerge(t *testing.T) {
|
||||
yamlString := "a: Hello\n---\na: Goodbye\n"
|
||||
expected_output := "a: Goodbye\n"
|
||||
|
||||
encoder := NewYamlEncoder(ConfiguredYamlPreferences)
|
||||
decoder := NewYamlDecoder(ConfiguredYamlPreferences)
|
||||
result, err := NewStringEvaluator().EvaluateAll("select(di==0) * select(di==1)", yamlString, encoder, decoder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
test.AssertResult(t, expected_output, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringEvaluator_Evaluate_Nominal(t *testing.T) {
|
||||
expected_output := `` +
|
||||
`yq` + "\n" +
|
||||
@@ -24,7 +38,7 @@ func TestStringEvaluator_Evaluate_Nominal(t *testing.T) {
|
||||
result, err := NewStringEvaluator().Evaluate(expression, input, encoder, decoder)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
test.AssertResult(t, expected_output, result)
|
||||
}
|
||||
|
||||
test.AssertResult(t, expected_output, result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user