more refinement

This commit is contained in:
Mike Farah 2020-10-17 22:58:18 +11:00
parent 5e544a5b7e
commit b026ebf2c3
3 changed files with 20 additions and 74 deletions

View File

@ -628,80 +628,6 @@ func TestDataTreeNavigatorArraySimple(t *testing.T) {
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) {
nodes := readDoc(t, `a:

View File

@ -29,6 +29,24 @@ var assignOperatorScenarios = []expressionScenario{
expected: []string{
"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: `{}`,
// expression: `["cat", "dog"]`,
// expected: []string{

View File

@ -18,11 +18,13 @@ func testScenario(t *testing.T, s *expressionScenario) {
path, errPath := treeCreator.ParsePath(s.expression)
if errPath != nil {
t.Error(errPath)
return
}
results, errNav := treeNavigator.GetMatchingNodes(nodes, path)
if errNav != nil {
t.Error(errNav)
return
}
test.AssertResultComplexWithContext(t, s.expected, resultsToString(results), s.expression)
}