mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 20:15:57 +00:00
more refinement
This commit is contained in:
parent
5e544a5b7e
commit
b026ebf2c3
@ -628,80 +628,6 @@ func TestDataTreeNavigatorArraySimple(t *testing.T) {
|
|||||||
test.AssertResult(t, expected, resultsToString(results))
|
test.AssertResult(t, expected, resultsToString(results))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDataTreeNavigatorSimpleAssignBooleanCmd(t *testing.T) {
|
|
||||||
|
|
||||||
nodes := readDoc(t, `a:
|
|
||||||
b: apple`)
|
|
||||||
path, errPath := treeCreator.ParsePath(`.a.b |= true`)
|
|
||||||
if errPath != nil {
|
|
||||||
t.Error(errPath)
|
|
||||||
}
|
|
||||||
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
|
||||||
|
|
||||||
if errNav != nil {
|
|
||||||
t.Error(errNav)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := `
|
|
||||||
-- Node --
|
|
||||||
Document 0, path: [a b]
|
|
||||||
Tag: !!bool, Kind: ScalarNode, Anchor:
|
|
||||||
true
|
|
||||||
`
|
|
||||||
|
|
||||||
test.AssertResult(t, expected, resultsToString(results))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDataTreeNavigatorSimpleAssignChildCmd(t *testing.T) {
|
|
||||||
|
|
||||||
nodes := readDoc(t, `a:
|
|
||||||
b: {g: 3}`)
|
|
||||||
|
|
||||||
path, errPath := treeCreator.ParsePath(`.a |= .b`)
|
|
||||||
if errPath != nil {
|
|
||||||
t.Error(errPath)
|
|
||||||
}
|
|
||||||
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
|
||||||
|
|
||||||
if errNav != nil {
|
|
||||||
t.Error(errNav)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := `
|
|
||||||
-- Node --
|
|
||||||
Document 0, path: [a]
|
|
||||||
Tag: !!map, Kind: MappingNode, Anchor:
|
|
||||||
{g: 3}
|
|
||||||
`
|
|
||||||
|
|
||||||
test.AssertResult(t, expected, resultsToString(results))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDataTreeNavigatorSimpleAssignSelf(t *testing.T) {
|
|
||||||
|
|
||||||
nodes := readDoc(t, `a:
|
|
||||||
b: apple`)
|
|
||||||
|
|
||||||
path, errPath := treeCreator.ParsePath("a(. == apple)(. := frog)")
|
|
||||||
if errPath != nil {
|
|
||||||
t.Error(errPath)
|
|
||||||
}
|
|
||||||
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
|
||||||
|
|
||||||
if errNav != nil {
|
|
||||||
t.Error(errNav)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := `
|
|
||||||
-- Node --
|
|
||||||
Document 0, path: [a b]
|
|
||||||
Tag: !!str, Kind: ScalarNode, Anchor:
|
|
||||||
frog
|
|
||||||
`
|
|
||||||
|
|
||||||
test.AssertResult(t, expected, resultsToString(results))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDataTreeNavigatorSimpleAssignByFind(t *testing.T) {
|
func TestDataTreeNavigatorSimpleAssignByFind(t *testing.T) {
|
||||||
|
|
||||||
nodes := readDoc(t, `a:
|
nodes := readDoc(t, `a:
|
||||||
|
@ -29,6 +29,24 @@ var assignOperatorScenarios = []expressionScenario{
|
|||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: {b: 3.142}}\n",
|
"D0, P[], (!!map)::{a: {b: 3.142}}\n",
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {b: {g: foof}}}`,
|
||||||
|
expression: `.a |= .b`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {g: foof}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `{a: {b: apple, c: cactus}}`,
|
||||||
|
expression: `.a[] | select(. == "apple") |= "frog"`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::{a: {b: frog, c: cactus}}\n",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
document: `[candy, apple, sandy]`,
|
||||||
|
expression: `.[] | select(. == "*andy") |= "bogs"`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!seq)::[bogs, apple, bogs]\n",
|
||||||
|
},
|
||||||
// document: `{}`,
|
// document: `{}`,
|
||||||
// expression: `["cat", "dog"]`,
|
// expression: `["cat", "dog"]`,
|
||||||
// expected: []string{
|
// expected: []string{
|
||||||
|
@ -18,11 +18,13 @@ func testScenario(t *testing.T, s *expressionScenario) {
|
|||||||
path, errPath := treeCreator.ParsePath(s.expression)
|
path, errPath := treeCreator.ParsePath(s.expression)
|
||||||
if errPath != nil {
|
if errPath != nil {
|
||||||
t.Error(errPath)
|
t.Error(errPath)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
|
||||||
|
|
||||||
if errNav != nil {
|
if errNav != nil {
|
||||||
t.Error(errNav)
|
t.Error(errNav)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
test.AssertResultComplexWithContext(t, s.expected, resultsToString(results), s.expression)
|
test.AssertResultComplexWithContext(t, s.expected, resultsToString(results), s.expression)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user