mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Comment processing fixes
This commit is contained in:
parent
49b8eafaf5
commit
f7c057b167
@ -82,7 +82,11 @@ func (ye *yamlEncoder) PrintLeadingContent(writer io.Writer, content string) err
|
|||||||
func (ye *yamlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
|
func (ye *yamlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
|
||||||
log.Debug("encoderYaml - going to print %v", NodeToString(node))
|
log.Debug("encoderYaml - going to print %v", NodeToString(node))
|
||||||
if node.Kind == ScalarNode && ye.prefs.UnwrapScalar {
|
if node.Kind == ScalarNode && ye.prefs.UnwrapScalar {
|
||||||
return writeString(writer, node.Value+"\n")
|
valueToPrint := node.Value
|
||||||
|
if node.LeadingContent == "" || valueToPrint != "" {
|
||||||
|
valueToPrint = valueToPrint + "\n"
|
||||||
|
}
|
||||||
|
return writeString(writer, valueToPrint)
|
||||||
}
|
}
|
||||||
|
|
||||||
destination := writer
|
destination := writer
|
||||||
|
@ -266,7 +266,25 @@ var commentOperatorScenarios = []expressionScenario{
|
|||||||
document: " # hi",
|
document: " # hi",
|
||||||
expression: `.`,
|
expression: `.`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!null):: # hi\n\n",
|
"D0, P[], (!!null):: # hi\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "string spaces",
|
||||||
|
skipDoc: true,
|
||||||
|
document: "# hi\ncat\n",
|
||||||
|
expression: `.`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!str)::# hi\ncat\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "leading spaces with new line",
|
||||||
|
skipDoc: true,
|
||||||
|
document: " # hi\n",
|
||||||
|
expression: `.`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!null):: # hi\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -275,7 +293,7 @@ var commentOperatorScenarios = []expressionScenario{
|
|||||||
document: "%YAML 1.1\n# hi\n",
|
document: "%YAML 1.1\n# hi\n",
|
||||||
expression: `.`,
|
expression: `.`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!null)::%YAML 1.1\n# hi\n\n",
|
"D0, P[], (!!null)::%YAML 1.1\n# hi\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ var loadScenarios = []expressionScenario{
|
|||||||
description: "Load empty file with a comment",
|
description: "Load empty file with a comment",
|
||||||
expression: `load("../../examples/empty.yaml")`,
|
expression: `load("../../examples/empty.yaml")`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!null)::# comment\n\n",
|
"D0, P[], (!!null)::# comment\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user