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"
|
2022-10-28 03:16:46 +00:00
|
|
|
encoder := NewYamlEncoder(2, true, ConfiguredYamlPreferences)
|
|
|
|
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)
|
|
|
|
}
|