2023-04-13 04:34:34 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mikefarah/yq/v4/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
var yamlScenarios = []formatScenario{
|
|
|
|
{
|
2023-04-13 04:44:39 +00:00
|
|
|
description: "basic - null",
|
2023-04-13 04:34:34 +00:00
|
|
|
skipDoc: true,
|
2023-04-13 04:44:39 +00:00
|
|
|
input: "null",
|
|
|
|
expected: "null\n",
|
2023-04-13 04:34:34 +00:00
|
|
|
},
|
|
|
|
// {
|
2023-04-13 04:44:39 +00:00
|
|
|
// description: "basic - ~",
|
2023-04-13 04:34:34 +00:00
|
|
|
// skipDoc: true,
|
2023-04-13 04:44:39 +00:00
|
|
|
// input: "~",
|
|
|
|
// expected: "~\n",
|
2023-04-13 04:34:34 +00:00
|
|
|
// },
|
2023-04-13 04:44:39 +00:00
|
|
|
{
|
|
|
|
description: "basic - [null]",
|
|
|
|
skipDoc: true,
|
|
|
|
input: "[null]",
|
|
|
|
expected: "[null]\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "basic - [~]",
|
|
|
|
skipDoc: true,
|
|
|
|
input: "[~]",
|
|
|
|
expected: "[~]\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "basic - null map value",
|
|
|
|
skipDoc: true,
|
|
|
|
input: "a: null",
|
|
|
|
expected: "a: null\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "basic - number",
|
|
|
|
skipDoc: true,
|
|
|
|
input: "3",
|
|
|
|
expected: "3\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "basic - float",
|
|
|
|
skipDoc: true,
|
|
|
|
input: "3.1",
|
|
|
|
expected: "3.1\n",
|
|
|
|
},
|
2023-04-13 04:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testYamlScenario(t *testing.T, s formatScenario) {
|
|
|
|
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYamlScenarios(t *testing.T) {
|
|
|
|
for _, tt := range yamlScenarios {
|
|
|
|
testYamlScenario(t, tt)
|
|
|
|
}
|
|
|
|
}
|