add check to verify that index is always correct in test program

This commit is contained in:
2024-07-18 15:36:21 +01:00
parent a2549b9093
commit 117ffeba6e
2 changed files with 39 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ struct
end
end
| (_, _) => print "verified lines; no problems\n"
fun verifyLines (buffer: t) =
let
val (strings, lines) =
@@ -104,6 +105,41 @@ struct
verifyLineList (strings, lines)
end
fun calcIndexList (accIdx, lst) =
case lst of
[] => accIdx
| hd::tl =>
calcIndexList (String.size hd + accIdx, tl)
fun calcIndexStart lst = calcIndexList (0, lst)
fun verifyIndex (buffer: t) =
let
val bufferIdx = #idx buffer
val correctIdx = calcIndexStart (#leftStrings buffer)
val _ =
if bufferIdx = correctIdx then
print "idx is correct\n"
else
let
val msg = String.concat [
"idx is incorrect;",
"bufferIdx: ",
Int.toString bufferIdx,
"; correctIdx: ",
Int.toString correctIdx,
"\n"
]
val _ = print msg
val _ = raise Size
in
print msg
end
in
()
end
local
fun helpToString (acc, input) =
@@ -1703,7 +1739,7 @@ struct
val _ = println "1829; base case"
in
{ idx = prevIdx + String.size sub1
{ idx = prevIdx + sub1Length
, line =
(curLine - Vector.length leftLinesHd)
+ Vector.length sub1Lines

View File

@@ -19,6 +19,8 @@ struct
val gapBuffer =
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
else gapBuffer
val _ = LineGap.verifyIndex gapBuffer
val _ = LineGap.verifyLines gapBuffer
val ropeString = TinyRope.toString rope