From eebf793fbf2b6f41b89fe02e2263c9a26c978d49 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 14 Sep 2025 12:54:23 +0100 Subject: [PATCH] refactor test code to check if textLength and lineLength are also correct --- src/line_gap.sml | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/line_gap.sml b/src/line_gap.sml index e553ebb..0686afa 100644 --- a/src/line_gap.sml +++ b/src/line_gap.sml @@ -3038,23 +3038,23 @@ struct goToStart (lsTl, llTl, lsHd :: accStrings, llHd :: accLines) | (_, _) => (accStrings, accLines) - fun verifyLineList (strings, lines) = + fun isLineListCorrect (strings, lines) = case (strings, lines) of (strHd :: strTl, lHd :: lTl) => let val checkLines = countLineBreaks strHd in if checkLines = lHd then - verifyLineList (strTl, lTl) + isLineListCorrect (strTl, lTl) else let val _ = print "line metadata is incorrect\n" val _ = checkLineBreaks (lHd, checkLines) in - raise Empty + false end end - | (_, _) => print "verified lines; no problems\n" + | (_, _) => (print "verified lines; no problems\n"; true) in fun verifyLines (buffer: t) = let @@ -3065,8 +3065,16 @@ struct , #rightStrings buffer , #rightLines buffer ) + + val lineListIsCorrect = isLineListCorrect (strings, lines) + val lineLengthIsCorrect = let val lines = Vector.concat lines + in Vector.length lines = #lineLength buffer + end + val () = + if lineLengthIsCorrect then () else print "line length is incorrect\n" in - verifyLineList (strings, lines) + if lineLengthIsCorrect andalso lineListIsCorrect then () + else raise Fail "" end end @@ -3082,9 +3090,13 @@ struct let val bufferIdx = #idx buffer val correctIdx = calcIndexStart (#leftStrings buffer) + val idxIsCorrect = bufferIdx = correctIdx + + val textLength = #textLength buffer + val textLengthIsCorrect = textLength = correctIdx val _ = - if bufferIdx = correctIdx then + if idxIsCorrect then print "idx is correct\n" else let @@ -3096,13 +3108,30 @@ struct , Int.toString correctIdx , "\n" ] - val _ = print msg - val _ = raise Size in print msg end + + val _ = + if textLengthIsCorrect then + print "textLength is correct" + else + let + val msg = String.concat + [ "text length is incorrect;" + , "text length: " + , Int.toString textLength + , "; correct length: " + , Int.toString correctIdx + , "\n" + ] + in + print msg + end + in - () + if textLengthIsCorrect andalso idxIsCorrect then () + else raise Fail "either index or text length is incorrect" end end end