2022-07-31 22:50:56 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mikefarah/yq/v4/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringEvaluator_Evaluate_Nominal(t *testing.T) {
|
|
|
|
expected_output := `` +
|
|
|
|
`yq` + "\n" +
|
|
|
|
`---` + "\n" +
|
|
|
|
`jq` + "\n"
|
|
|
|
expression := ".[].name"
|
|
|
|
input := `` +
|
|
|
|
` - name: yq` + "\n" +
|
|
|
|
` description: yq is a portable command-line YAML, JSON and XML processor` + "\n" +
|
|
|
|
`---` + "\n" +
|
|
|
|
` - name: jq` + "\n" +
|
|
|
|
` description: Command-line JSON processor` + "\n"
|
2024-02-24 04:36:16 +00:00
|
|
|
encoder := NewYamlEncoder(ConfiguredYamlPreferences)
|
2022-10-28 03:16:46 +00:00
|
|
|
decoder := NewYamlDecoder(ConfiguredYamlPreferences)
|
2022-07-31 22:50:56 +00:00
|
|
|
|
2022-10-28 03:16:46 +00:00
|
|
|
result, err := NewStringEvaluator().Evaluate(expression, input, encoder, decoder)
|
2022-07-31 22:50:56 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
test.AssertResult(t, expected_output, result)
|
|
|
|
}
|