Permalink
Browse files

Fix flatMap's setting of update times.

  • Loading branch information...
josharnold52 committed Oct 19, 2011
1 parent effe767 commit ffe5b2151d7ce2d99a5b1bb52ea742e595bb1eb1
@@ -217,7 +217,7 @@ trait Zipper[+A <: Node] extends Group[A] with IndexedSeqLike[A, Zipper[A]] { se
val b = cpz.lift(parent, this)
for(i <- 0 until nodes.length) {
val (path,time) = metas(i)
- b += ElemsWithContext(path, time, f(nodes(i)))
+ b += ElemsWithContext(path, time+i+1, f(nodes(i)))
}
for ((path,time) <- additionalHoles) {
b += ElemsWithContext[B](path,time,util.Vector0)
@@ -936,6 +936,25 @@ class ZipperSpecs extends SpecificationWithJUnit with ScalaCheck with XMLGenera
}
}
+ "Zipper.flatMap" should {
+ "increase update times front to back" in {
+ val xml = <top><a><b /></a></top>.convert
+ val z = xml \\ *
+
+ //Conflicting updates. First node has latest update time.
+ val z1 = z.updated(1,elem("b2"))
+ val z2 = z1.updated(0,elem("a",elem("c")))
+
+ //Apply a flatMap, which will make the second node have the latest update time
+ val z3 = z2 flatMap {n => Seq(n)}
+
+ z2.unselect mustEqual <top><a><c /></a></top>.convert.toGroup
+ z3.unselect mustEqual <top><a><b2 /></a></top>.convert.toGroup
+
+ }
+ }
+
+
def validate[Expected] = new {
def apply[A](a: A)(implicit evidence: A =:= Expected) = evidence must not beNull
}

0 comments on commit ffe5b21

Please sign in to comment.