add check to verify that index is always correct in test program
This commit is contained in:
@@ -91,6 +91,7 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
| (_, _) => print "verified lines; no problems\n"
|
| (_, _) => print "verified lines; no problems\n"
|
||||||
|
|
||||||
fun verifyLines (buffer: t) =
|
fun verifyLines (buffer: t) =
|
||||||
let
|
let
|
||||||
val (strings, lines) =
|
val (strings, lines) =
|
||||||
@@ -104,6 +105,41 @@ struct
|
|||||||
verifyLineList (strings, lines)
|
verifyLineList (strings, lines)
|
||||||
end
|
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
|
local
|
||||||
fun helpToString (acc, input) =
|
fun helpToString (acc, input) =
|
||||||
@@ -1703,7 +1739,7 @@ struct
|
|||||||
|
|
||||||
val _ = println "1829; base case"
|
val _ = println "1829; base case"
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size sub1
|
{ idx = prevIdx + sub1Length
|
||||||
, line =
|
, line =
|
||||||
(curLine - Vector.length leftLinesHd)
|
(curLine - Vector.length leftLinesHd)
|
||||||
+ Vector.length sub1Lines
|
+ Vector.length sub1Lines
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ struct
|
|||||||
val gapBuffer =
|
val gapBuffer =
|
||||||
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
|
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
|
||||||
else gapBuffer
|
else gapBuffer
|
||||||
|
|
||||||
|
val _ = LineGap.verifyIndex gapBuffer
|
||||||
val _ = LineGap.verifyLines gapBuffer
|
val _ = LineGap.verifyLines gapBuffer
|
||||||
|
|
||||||
val ropeString = TinyRope.toString rope
|
val ropeString = TinyRope.toString rope
|
||||||
|
|||||||
Reference in New Issue
Block a user