verified through testing that insertion works as expected as far as contents of string is concerned. However, have added print statements which I need to remove when I have a fully working implementation

This commit is contained in:
2024-06-30 00:50:38 +01:00
parent de087a86d5
commit 6af253eed9
4 changed files with 108 additions and 17 deletions

BIN
tests/compare Executable file

Binary file not shown.

16
tests/compare.mlb Normal file
View File

@@ -0,0 +1,16 @@
$(SML_LIB)/basis/basis.mlb
ann
"allowVectorExps true"
in
../data-sets/svelte.sml
(*
../data-sets/rust.sml
../data-sets/seph.sml
../data-sets/automerge.sml
*)
end
../src/tiny_rope.sml
../src/line_gap.sml
compare_to_rope.sml

View File

@@ -1,16 +1,67 @@
structure CompareToRope =
struct
local
fun folder ((pos, delNum, insStr), buffer, fIns, fDel) =
let
val buffer =
if String.size insStr > 0 then
fIns (pos, insStr, buffer) else buffer
in
buffer
end
fun compareTxns arr =
Vector.foldli
(fn (idx, (pos, delNum, insStr), (rope, gapBuffer)) =>
let
val _ = print ("idx: " ^ Int.toString idx ^ "\n")
val oldRope = rope
val strSize = String.size insStr
val rope =
if strSize > 0 then TinyRope.insert (pos, insStr, rope) else rope
val gapBuffer =
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
else gapBuffer
val ropeString = TinyRope.toString rope
val gapBufferString = LineGap.toString gapBuffer
in
if ropeString = gapBufferString then
(rope, gapBuffer)
else
let
val _ = print
("difference detected at txn number: " ^ (Int.toString idx)
^ "\n")
val txn = String.concat
[ "offending txn: \n"
, "pos: "
, Int.toString pos
, ", delNum: "
, Int.toString delNum
, ", insStr: |"
, insStr
, "|\n"
]
val _ = print txn
val _ = print "before offending string: \n"
val _ = print (TinyRope.toString oldRope)
val _ = print "\n"
val _ = print "rope string: \n"
val _ = print (ropeString ^ "\n")
val _ = print "gap string: \n"
val _ = print (gapBufferString ^ "\n")
val _ = raise Empty
in
(rope, gapBuffer)
end
end) (TinyRope.empty, LineGap.empty) arr
fun main () =
let
val _ = compareTxns SvelteComponent.txns
(*
val _ = compareTxns Rust.txns
val _ = compareTxns Seph.txns
val _ = compareTxns Automerge.txns
*)
in
fun runTxns () =
Vector.foldl folder Txn.empty Txn.txns
()
end
val _ = main ()
end