diff --git a/src/line_gap.sml b/src/line_gap.sml index 001b976..b08a408 100644 --- a/src/line_gap.sml +++ b/src/line_gap.sml @@ -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 diff --git a/tests/compare_to_rope.sml b/tests/compare_to_rope.sml index 6e32142..d5bcf8e 100644 --- a/tests/compare_to_rope.sml +++ b/tests/compare_to_rope.sml @@ -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