yq/pkg/yqlib/yaml_test.go
Mike Farah c38841ce20 wip
2023-04-13 15:40:41 +10:00

78 lines
1.5 KiB
Go

package yqlib
import (
"testing"
"github.com/mikefarah/yq/v4/test"
)
var yamlFormatScenarios = []formatScenario{
{
description: "basic - null",
skipDoc: true,
input: "null",
expected: "null\n",
},
// {
// description: "basic - ~",
// skipDoc: true,
// input: "~",
// expected: "~\n",
// },
{
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",
},
}
var yamlParseScenarios = []expressionScenario{
{
document: `a: hello # things`,
expected: []string{
"D0, P[], (doc)::a: hello #things\n",
},
},
}
func testYamlScenario(t *testing.T, s formatScenario) {
test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewYamlDecoder(ConfiguredYamlPreferences), NewYamlEncoder(2, false, ConfiguredYamlPreferences)), s.description)
}
func TestYamlParseScenarios(t *testing.T) {
for _, tt := range yamlParseScenarios {
testScenario(t, &tt)
}
}
func TestYamlFormatScenarios(t *testing.T) {
for _, tt := range yamlFormatScenarios {
testYamlScenario(t, tt)
}
}