mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 02:03:24 +08:00
feat(toml): fix JSON to TOML root scope and null handling (#2689)
Ensure root-level TOML attributes are emitted before table sections so fields like sort remain root-scoped. Skip null-valued object fields during TOML encoding
instead of converting them to empty strings.
This commit is contained in:
@@ -892,6 +892,60 @@ func TestTomlScenarios(t *testing.T) {
|
||||
documentScenarios(t, "usage", "toml", genericScenarios, documentTomlScenario)
|
||||
}
|
||||
|
||||
func TestTomlEncodeJsonKeepsRootArrayBeforeTables(t *testing.T) {
|
||||
scenario := formatScenario{
|
||||
description: "Encode: JSON root array stays outside later tables",
|
||||
input: `{
|
||||
"_source": {
|
||||
"cookie": [
|
||||
{
|
||||
"Domain": "",
|
||||
"Expires": "0001-01-01T00:00:00Z",
|
||||
"HttpOnly": false,
|
||||
"MaxAge": 0,
|
||||
"Name": "name",
|
||||
"Path": "",
|
||||
"Raw": "",
|
||||
"RawExpires": "",
|
||||
"SameSite": 0,
|
||||
"Secure": false,
|
||||
"Unparsed": null,
|
||||
"Value": "value"
|
||||
}
|
||||
]
|
||||
},
|
||||
"highlight": {
|
||||
"did": [
|
||||
"did"
|
||||
]
|
||||
},
|
||||
"sort": [
|
||||
1
|
||||
]
|
||||
}`,
|
||||
expected: `sort = [1]
|
||||
|
||||
[[_source.cookie]]
|
||||
Domain = ""
|
||||
Expires = "0001-01-01T00:00:00Z"
|
||||
HttpOnly = false
|
||||
MaxAge = 0
|
||||
Name = "name"
|
||||
Path = ""
|
||||
Raw = ""
|
||||
RawExpires = ""
|
||||
SameSite = 0
|
||||
Secure = false
|
||||
Value = "value"
|
||||
|
||||
[highlight]
|
||||
did = ["did"]
|
||||
`,
|
||||
}
|
||||
|
||||
test.AssertResultWithContext(t, scenario.expected, mustProcessFormatScenario(scenario, NewJSONDecoder(), NewTomlEncoder()), scenario.description)
|
||||
}
|
||||
|
||||
// TestTomlColourization tests that colourization correctly distinguishes
|
||||
// between table section headers and inline arrays
|
||||
func TestTomlColourization(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user