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
|
||||
func (n *CandidateNode) UpdateFrom(other *CandidateNode) {
|
||||
|
||||
n.UpdateAttributesFrom(other)
|
||||
n.Node.Content = other.Node.Content
|
||||
n.Node.Value = other.Node.Value
|
||||
n.UpdateAttributesFrom(other)
|
||||
}
|
||||
|
||||
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.Tag = other.Node.Tag
|
||||
n.Node.Style = other.Node.Style
|
||||
|
@ -19,6 +19,7 @@ func readDoc(t *testing.T, content string) []*CandidateNode {
|
||||
var dataBucket yaml.Node
|
||||
err := decoder.Decode(&dataBucket)
|
||||
if err != nil {
|
||||
t.Error(content)
|
||||
t.Error(err)
|
||||
}
|
||||
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 newMatches = make([]*CandidateNode, len(contents))
|
||||
|
||||
for index := 0; index < len(contents); index = index + 1 {
|
||||
var index int64
|
||||
for index = 0; index < int64(len(contents)); index = index + 1 {
|
||||
newMatches[index] = &CandidateNode{
|
||||
Document: candidate.Document,
|
||||
Path: append(candidate.Path, index),
|
||||
|
@ -6,17 +6,61 @@ import (
|
||||
|
||||
var multiplyOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
// document: `{a: frog, b: cat}`,
|
||||
// expression: `.a * .b`,
|
||||
// expected: []string{
|
||||
// "D0, P[], (!!map)::{a: cat, b: cat}\n",
|
||||
// },
|
||||
// }, {
|
||||
document: `{a: {also: [1]}, b: {also: me}}`,
|
||||
expression: `.a * .b`,
|
||||
expected: []string{
|
||||
"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}}`,
|
||||
expression: `.a * .b`,
|
||||
expected: []string{
|
||||
"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