mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
3beee3f804
Adds check if the key is an `int` or `bool`, and converts to a string as part of the `toJSON` function. Test cases added. Resolves: #28
43 lines
684 B
Go
43 lines
684 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestJsonToString(t *testing.T) {
|
|
var data = parseData(`
|
|
---
|
|
b:
|
|
c: 2
|
|
`)
|
|
assertResult(t, "{\"b\":{\"c\":2}}", jsonToString(data))
|
|
}
|
|
|
|
func TestJsonToString_withIntKey(t *testing.T) {
|
|
var data = parseData(`
|
|
---
|
|
b:
|
|
2: c
|
|
`)
|
|
assertResult(t, `{"b":{"2":"c"}}`, jsonToString(data))
|
|
}
|
|
|
|
func TestJsonToString_withBoolKey(t *testing.T) {
|
|
var data = parseData(`
|
|
---
|
|
b:
|
|
false: c
|
|
`)
|
|
assertResult(t, `{"b":{"false":"c"}}`, jsonToString(data))
|
|
}
|
|
|
|
func TestJsonToString_withArray(t *testing.T) {
|
|
var data = parseData(`
|
|
---
|
|
b:
|
|
- item: one
|
|
- item: two
|
|
`)
|
|
assertResult(t, "{\"b\":[{\"item\":\"one\"},{\"item\":\"two\"}]}", jsonToString(data))
|
|
}
|