From a0c9235a36e5409bd9b6c09150b5db7485d543f6 Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@protonmail.com>
Date: Mon, 4 Apr 2022 16:35:50 +0200
Subject: [PATCH] fix test-move logic

---
 src/utils/ListIterator.js |  3 ---
 tests/y-array.tests.js    | 12 ++++++++----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/utils/ListIterator.js b/src/utils/ListIterator.js
index 0f297173..146a2a98 100644
--- a/src/utils/ListIterator.js
+++ b/src/utils/ListIterator.js
@@ -49,9 +49,6 @@ const popMovedStack = (tr, li) => {
       const coords = getMovedCoords(moveContent, tr)
       start = coords.start
       end = coords.end
-      // @todo why are we not running into this?
-      console.log('found edge case 42') // @todo remove
-      debugger
     }
   }
   li.currMove = move
diff --git a/tests/y-array.tests.js b/tests/y-array.tests.js
index 15f59366..baa2acb0 100644
--- a/tests/y-array.tests.js
+++ b/tests/y-array.tests.js
@@ -563,11 +563,15 @@ const arrayTransactions = [
       return
     }
     const pos = prng.int32(gen, 0, yarray.length - 1)
-    const newPos = prng.int32(gen, 0, yarray.length)
+    const len = 1 // prng.int32(gen, 1, math.min(3, yarray.length - pos))
+    const _newPosAdj = prng.int32(gen, 0, yarray.length - len)
+    // make sure that we don't insert in-between the moved range
+    const newPos = _newPosAdj + (_newPosAdj > yarray.length - len ? len : 0)
     const oldContent = yarray.toArray()
-    yarray.move(pos, newPos)
-    const [x] = oldContent.splice(pos, 1)
-    oldContent.splice(pos < newPos ? newPos - 1 : newPos, 0, x)
+    yarray.moveRange(pos, pos + len - 1, newPos)
+    console.log(`moving range ${pos}-${pos + len} to ${newPos}`)
+    const movedValues = oldContent.splice(pos, len)
+    oldContent.splice(pos < newPos ? newPos - len : newPos, 0, ...movedValues)
     t.compareArrays(yarray.toArray(), oldContent) // we want to make sure that fastSearch markers insert at the correct position
   },
   function insert (user, gen) {