mirror of
https://github.com/mikefarah/yq.git
synced 2025-03-14 15:55:37 +00:00
Fixed explode anchors for array roots
This commit is contained in:
parent
5cc01e43bc
commit
96a4161a92
@ -322,6 +322,36 @@ pointer: *value-pointer`
|
|||||||
test.AssertResult(t, expectedOutput, result.Output)
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadMergeAnchorsExplodeSimpleArrayCmd(t *testing.T) {
|
||||||
|
content := `- things`
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("read -X %s", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := `- things
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadMergeAnchorsExplodeSimpleArrayJsonCmd(t *testing.T) {
|
||||||
|
content := `- things`
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("read -j %s", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := `["things"]
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadMergeAnchorsExplodeSimpleValueForValueCmd(t *testing.T) {
|
func TestReadMergeAnchorsExplodeSimpleValueForValueCmd(t *testing.T) {
|
||||||
content := `value: &value-pointer the value
|
content := `value: &value-pointer the value
|
||||||
pointer: *value-pointer`
|
pointer: *value-pointer`
|
||||||
|
@ -115,9 +115,9 @@ func writeString(writer io.Writer, txt string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func explode(matchingNodes []*yqlib.NodeContext) error {
|
func explode(matchingNodes []*yqlib.NodeContext) error {
|
||||||
|
log.Debug("exploding nodes")
|
||||||
for _, nodeContext := range matchingNodes {
|
for _, nodeContext := range matchingNodes {
|
||||||
var targetNode = yaml.Node{Kind: yaml.MappingNode}
|
var targetNode = yaml.Node{Kind: nodeContext.Node.Kind}
|
||||||
explodedNodes, errorRetrieving := lib.Get(nodeContext.Node, "**", true)
|
explodedNodes, errorRetrieving := lib.Get(nodeContext.Node, "**", true)
|
||||||
if errorRetrieving != nil {
|
if errorRetrieving != nil {
|
||||||
return errorRetrieving
|
return errorRetrieving
|
||||||
@ -132,6 +132,7 @@ func explode(matchingNodes []*yqlib.NodeContext) error {
|
|||||||
}
|
}
|
||||||
nodeContext.Node = &targetNode
|
nodeContext.Node = &targetNode
|
||||||
}
|
}
|
||||||
|
log.Debug("done exploding nodes")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user