mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
26a09e6ec0
- Move data_navigator, json_converter, merge, and path_parser to pkg/yqlib - Extract yamlToString from yq to pkg/yqlib/yaml_converter - Move utils_test to test/utils
48 lines
817 B
Go
48 lines
817 B
Go
package yqlib
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/mikefarah/yq/test"
|
|
)
|
|
|
|
func TestJsonToString(t *testing.T) {
|
|
var data = test.ParseData(`
|
|
---
|
|
b:
|
|
c: 2
|
|
`)
|
|
got, _ := JsonToString(data)
|
|
test.AssertResult(t, "{\"b\":{\"c\":2}}", got)
|
|
}
|
|
|
|
func TestJsonToString_withIntKey(t *testing.T) {
|
|
var data = test.ParseData(`
|
|
---
|
|
b:
|
|
2: c
|
|
`)
|
|
got, _ := JsonToString(data)
|
|
test.AssertResult(t, `{"b":{"2":"c"}}`, got)
|
|
}
|
|
|
|
func TestJsonToString_withBoolKey(t *testing.T) {
|
|
var data = test.ParseData(`
|
|
---
|
|
b:
|
|
false: c
|
|
`)
|
|
got, _ := JsonToString(data)
|
|
test.AssertResult(t, `{"b":{"false":"c"}}`, got)
|
|
}
|
|
|
|
func TestJsonToString_withArray(t *testing.T) {
|
|
var data = test.ParseData(`
|
|
---
|
|
b:
|
|
- item: one
|
|
- item: two
|
|
`)
|
|
got, _ := JsonToString(data)
|
|
test.AssertResult(t, "{\"b\":[{\"item\":\"one\"},{\"item\":\"two\"}]}", got)
|
|
}
|