Closed victor-axelsson closed 7 years ago
Now, you can do a simple insertAfter with the following unit test:
val eval = new Evaluator(1)
val insertSomeIndex = InsertAfter(new Str("someIndex"))
eval evalExpr Doc() evalExpr Get("someVar") evalExpr Get("someVar2") evalExpr Idx(0) evalCmd insertSomeIndex
val s:String = eval.toJsonString()
Where the s will be equal to:
{"doc":{"someVar":{"someVar2":["[0]":"someIndex"]}}}
I kept the index as the variable name. What i would like to see is that the addAtIndex
function on the NodeList
actually works properly.
It would be nice to test the following
If you want to get into the code a good place to start is in the insert
function in the context class.
val insert:Insert = context.op.getMutation().asInstanceOf[Insert]
val index:Int = context.op.getCursor().getId().getKey().toInt
var key:Key = null;
val name:String = "[" + index + "]"
val node:Node = insert.value match {
case s @ EmptyMap => {
key = mapT(name)
new NodeMap(name, new scala.collection.immutable.HashMap[Int, Operation]())
}
case s @ EmptyList => {
key = listT(name)
new NodeList(name, new scala.collection.immutable.HashMap[Int, Operation]())
}
case s @ _ => {
key = regT(name)
var values = List[Val]()
values = values :+ s
new NodeReg(name, values, new scala.collection.immutable.HashMap[Int, Operation]())
}
}
clear(context.op.getDeps(), key)
context.child.asInstanceOf[NodeList].insertAt(index, node)
addId(key.getKey(), context.op, context.child)
I've fixed most of the stuff here. But I didn't test:
I think the first one is a little silly, it will insert at the end if you use a bigger index. THe second one I didn't do because we don't have proper delete yet.
About
We should be able to perform an insertAfter. This unit test was started, as you can see in CmdEvalTest, where it is commented out. In order to continue we need the
idx(<int>)
to be implementedEDIT: We now have enough idx logic in order to test it. However, this does not mean that idx is done.