mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 20:15:57 +00:00
Fixed trailing empty docs
This commit is contained in:
parent
44322f0248
commit
ceb76e5c17
@ -1264,6 +1264,30 @@ func TestWriteEmptyMultiDocCmd(t *testing.T) {
|
|||||||
test.AssertResult(t, expectedOutput, result.Output)
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriteTrailingEmptyMultiDocCmd(t *testing.T) {
|
||||||
|
content := `cat: frog
|
||||||
|
---
|
||||||
|
|
||||||
|
# empty
|
||||||
|
`
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("write %s c 7", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := `cat: frog
|
||||||
|
c: 7
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
# empty
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestWriteFromFileCmd(t *testing.T) {
|
func TestWriteFromFileCmd(t *testing.T) {
|
||||||
content := `b:
|
content := `b:
|
||||||
c: 3
|
c: 3
|
||||||
|
@ -226,7 +226,7 @@ func mapYamlDecoder(updateData updateDataFn, encoder yqlib.Encoder) yamlDecoderF
|
|||||||
dataBucket = yaml.Node{Kind: yaml.DocumentNode, Content: make([]*yaml.Node, 1)}
|
dataBucket = yaml.Node{Kind: yaml.DocumentNode, Content: make([]*yaml.Node, 1)}
|
||||||
child := yaml.Node{Kind: yaml.MappingNode}
|
child := yaml.Node{Kind: yaml.MappingNode}
|
||||||
dataBucket.Content[0] = &child
|
dataBucket.Content[0] = &child
|
||||||
} else if isNullDocument(&dataBucket) {
|
} else if isNullDocument(&dataBucket) && (updateAll || docIndexInt == currentIndex) {
|
||||||
child := yaml.Node{Kind: yaml.MappingNode}
|
child := yaml.Node{Kind: yaml.MappingNode}
|
||||||
dataBucket.Content[0] = &child
|
dataBucket.Content[0] = &child
|
||||||
} else if errorReading == io.EOF {
|
} else if errorReading == io.EOF {
|
||||||
|
Loading…
Reference in New Issue
Block a user