This commit is contained in:
Mike Farah 2020-10-10 23:04:10 +11:00
parent 0a2a3c4374
commit e6fd6905eb
2 changed files with 60 additions and 0 deletions

View File

@ -133,6 +133,65 @@ func TestDataTreeNavigatorSubtractWithUnion(t *testing.T) {
test.AssertResult(t, expected, resultsToString(results)) test.AssertResult(t, expected, resultsToString(results))
} }
func TestDataTreeNavigatorSubtractByIndex(t *testing.T) {
nodes := readDoc(t, `a:
- b: apple
- b: sdfsd
- b: apple`)
path, errPath := treeCreator.ParsePath("(a .- (0 or 1))")
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: !!seq, Kind: SequenceNode, Anchor:
- b: apple
`
test.AssertResult(t, expected, resultsToString(results))
}
func TestDataTreeNavigatorDeleteAndWrite(t *testing.T) {
nodes := readDoc(t, `a:
- b: apple
- b: sdfsd
- { b: apple, c: cat }`)
path, errPath := treeCreator.ParsePath("(a .- (0 or 1)) or (a[0].b := 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]
Tag: !!seq, Kind: SequenceNode, Anchor:
- {b: frog, c: cat}
-- Node --
Document 0, path: [a 0 b]
Tag: !!str, Kind: ScalarNode, Anchor:
frog
`
test.AssertResult(t, expected, resultsToString(results))
}
func TestDataTreeNavigatorSubtractArray(t *testing.T) { func TestDataTreeNavigatorSubtractArray(t *testing.T) {
nodes := readDoc(t, `a: nodes := readDoc(t, `a:

View File

@ -19,6 +19,7 @@ func AssignOperator(d *dataTreeNavigator, matchingNodes *orderedmap.OrderedMap,
} }
for el := lhs.Front(); el != nil; el = el.Next() { for el := lhs.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode) node := el.Value.(*CandidateNode)
log.Debugf("Assiging %v to %v", node.getKey(), pathNode.Rhs.PathElement.StringValue)
node.Node.Value = pathNode.Rhs.PathElement.StringValue node.Node.Value = pathNode.Rhs.PathElement.StringValue
} }
return lhs, nil return lhs, nil