More tests

This commit is contained in:
Mike Farah
2026-02-01 10:27:18 +11:00
parent 2be0094729
commit eb04fa87af
7 changed files with 576 additions and 8 deletions
+48 -2
View File
@@ -230,12 +230,16 @@ name = "Tom" # name comment
// Reproduce bug for https://github.com/mikefarah/yq/issues/2588
// Bug: standalone comments inside a table cause subsequent key-values to be assigned at root.
var issue2588RustToolchainWithComments = `
[owner]
var issue2588RustToolchainWithComments = `[owner]
# comment
name = "Tomer"
`
var tableWithComment = `[owner]
# comment
[things]
`
var sampleFromWeb = `# This is a TOML document
title = "TOML Example"
@@ -574,6 +578,19 @@ var tomlScenarios = []formatScenario{
expected: "null\n",
scenarioType: "decode",
},
{
skipDoc: true,
input: issue2588RustToolchainWithComments,
expected: issue2588RustToolchainWithComments,
scenarioType: "roundtrip",
},
{
skipDoc: true,
input: tableWithComment,
expression: ".owner | headComment",
expected: "comment\n",
scenarioType: "roundtrip",
},
{
description: "Roundtrip: sample from web",
input: sampleFromWeb,
@@ -933,3 +950,32 @@ func TestTomlStringEscapeColourization(t *testing.T) {
})
}
}
func TestTomlEncoderPrintDocumentSeparator(t *testing.T) {
encoder := NewTomlEncoder()
var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
err := encoder.PrintDocumentSeparator(writer)
writer.Flush()
test.AssertResult(t, nil, err)
test.AssertResult(t, "", buf.String())
}
func TestTomlEncoderPrintLeadingContent(t *testing.T) {
encoder := NewTomlEncoder()
var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
err := encoder.PrintLeadingContent(writer, "some content")
writer.Flush()
test.AssertResult(t, nil, err)
test.AssertResult(t, "", buf.String())
}
func TestTomlEncoderCanHandleAliases(t *testing.T) {
encoder := NewTomlEncoder()
test.AssertResult(t, false, encoder.CanHandleAliases())
}