2019-12-01 20:10:42 +00:00
|
|
|
package marshal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-12-04 05:10:28 +00:00
|
|
|
"github.com/mikefarah/yq/v2/test"
|
2019-12-01 20:10:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestYamlToString(t *testing.T) {
|
|
|
|
var raw = `b:
|
|
|
|
c: 2
|
|
|
|
`
|
|
|
|
var data = test.ParseData(raw)
|
|
|
|
got, _ := NewYamlConverter().YamlToString(data, false)
|
|
|
|
test.AssertResult(t, raw, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYamlToString_withTrim(t *testing.T) {
|
|
|
|
var raw = `b:
|
|
|
|
c: 2`
|
|
|
|
var data = test.ParseData(raw)
|
|
|
|
got, _ := NewYamlConverter().YamlToString(data, true)
|
|
|
|
test.AssertResult(t, raw, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYamlToString_withIntKey(t *testing.T) {
|
|
|
|
var raw = `b:
|
|
|
|
2: c
|
|
|
|
`
|
|
|
|
var data = test.ParseData(raw)
|
|
|
|
got, _ := NewYamlConverter().YamlToString(data, false)
|
|
|
|
test.AssertResult(t, raw, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYamlToString_withBoolKey(t *testing.T) {
|
|
|
|
var raw = `b:
|
|
|
|
false: c
|
|
|
|
`
|
|
|
|
var data = test.ParseData(raw)
|
|
|
|
got, _ := NewYamlConverter().YamlToString(data, false)
|
|
|
|
test.AssertResult(t, raw, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestYamlToString_withArray(t *testing.T) {
|
|
|
|
var raw = `b:
|
|
|
|
- item: one
|
|
|
|
- item: two
|
|
|
|
`
|
|
|
|
var data = test.ParseData(raw)
|
|
|
|
got, _ := NewYamlConverter().YamlToString(data, false)
|
|
|
|
test.AssertResult(t, raw, got)
|
|
|
|
}
|