mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
merge
This commit is contained in:
parent
2ddf8dd4ed
commit
1910563bfe
@ -20,13 +20,18 @@ func (n *CandidateNode) GetKey() string {
|
|||||||
|
|
||||||
// updates this candidate from the given candidate node
|
// updates this candidate from the given candidate node
|
||||||
func (n *CandidateNode) UpdateFrom(other *CandidateNode) {
|
func (n *CandidateNode) UpdateFrom(other *CandidateNode) {
|
||||||
|
n.UpdateAttributesFrom(other)
|
||||||
n.Node.Content = other.Node.Content
|
n.Node.Content = other.Node.Content
|
||||||
n.Node.Value = other.Node.Value
|
n.Node.Value = other.Node.Value
|
||||||
n.UpdateAttributesFrom(other)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode) {
|
func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode) {
|
||||||
|
if n.Node.Kind != other.Node.Kind {
|
||||||
|
// clear out the contents when switching to a different type
|
||||||
|
// e.g. map to array
|
||||||
|
n.Node.Content = make([]*yaml.Node, 0)
|
||||||
|
n.Node.Value = ""
|
||||||
|
}
|
||||||
n.Node.Kind = other.Node.Kind
|
n.Node.Kind = other.Node.Kind
|
||||||
n.Node.Tag = other.Node.Tag
|
n.Node.Tag = other.Node.Tag
|
||||||
n.Node.Style = other.Node.Style
|
n.Node.Style = other.Node.Style
|
||||||
|
@ -19,6 +19,7 @@ func readDoc(t *testing.T, content string) []*CandidateNode {
|
|||||||
var dataBucket yaml.Node
|
var dataBucket yaml.Node
|
||||||
err := decoder.Decode(&dataBucket)
|
err := decoder.Decode(&dataBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Error(content)
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
return []*CandidateNode{&CandidateNode{Node: dataBucket.Content[0], Document: 0}}
|
return []*CandidateNode{&CandidateNode{Node: dataBucket.Content[0], Document: 0}}
|
||||||
|
@ -69,8 +69,8 @@ func (t *traverser) traverseArray(candidate *CandidateNode, pathNode *PathElemen
|
|||||||
|
|
||||||
var contents = candidate.Node.Content
|
var contents = candidate.Node.Content
|
||||||
var newMatches = make([]*CandidateNode, len(contents))
|
var newMatches = make([]*CandidateNode, len(contents))
|
||||||
|
var index int64
|
||||||
for index := 0; index < len(contents); index = index + 1 {
|
for index = 0; index < int64(len(contents)); index = index + 1 {
|
||||||
newMatches[index] = &CandidateNode{
|
newMatches[index] = &CandidateNode{
|
||||||
Document: candidate.Document,
|
Document: candidate.Document,
|
||||||
Path: append(candidate.Path, index),
|
Path: append(candidate.Path, index),
|
||||||
|
@ -6,17 +6,61 @@ import (
|
|||||||
|
|
||||||
var multiplyOperatorScenarios = []expressionScenario{
|
var multiplyOperatorScenarios = []expressionScenario{
|
||||||
{
|
{
|
||||||
// document: `{a: frog, b: cat}`,
|
document: `{a: {also: [1]}, b: {also: me}}`,
|
||||||
// expression: `.a * .b`,
|
expression: `.a * .b`,
|
||||||
// expected: []string{
|
expected: []string{
|
||||||
// "D0, P[], (!!map)::{a: cat, b: cat}\n",
|
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
|
||||||
// },
|
},
|
||||||
// }, {
|
}, {
|
||||||
|
document: `{a: {also: me}, b: {also: [1]}}`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {also: [1]}, b: {also: [1]}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {also: me}, b: {also: {g: wizz}}}`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {also: {g: wizz}}, b: {also: {g: wizz}}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {also: {g: wizz}}, b: {also: me}}`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {also: me}, b: {also: me}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {also: {g: wizz}}, b: {also: [1]}}`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {also: [1]}, b: {also: [1]}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {also: [1]}, b: {also: {g: wizz}}}`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {also: {g: wizz}}, b: {also: {g: wizz}}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
document: `{a: {things: great}, b: {also: me}}`,
|
document: `{a: {things: great}, b: {also: me}}`,
|
||||||
expression: `.a * .b`,
|
expression: `.a * .b`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: {things: great, also: me}, b: {also: me}}\n",
|
"D0, P[], (!!map)::{a: {things: great, also: me}, b: {also: me}}\n",
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
document: `a: {things: great}
|
||||||
|
b:
|
||||||
|
also: "me"
|
||||||
|
`,
|
||||||
|
expression: `.a * .b`,
|
||||||
|
expected: []string{
|
||||||
|
`D0, P[], (!!map)::a:
|
||||||
|
things: great
|
||||||
|
also: "me"
|
||||||
|
b:
|
||||||
|
also: "me"
|
||||||
|
`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user