start testing correctness of line metadata
This commit is contained in:
@@ -2,34 +2,30 @@ structure LineGap =
|
|||||||
struct
|
struct
|
||||||
local
|
local
|
||||||
fun helpCountLineBreaks (pos, acc, str) =
|
fun helpCountLineBreaks (pos, acc, str) =
|
||||||
let
|
if pos < 0 then
|
||||||
val _ = print ("count pos: " ^ Int.toString pos ^ "\n")
|
Vector.fromList acc
|
||||||
in
|
else
|
||||||
if pos < 0 then
|
let
|
||||||
Vector.fromList acc
|
val chr = String.sub (str, pos)
|
||||||
else
|
in
|
||||||
let
|
if chr = #"\n" then
|
||||||
val chr = String.sub (str, pos)
|
(* Is this a \r\n pair? Then the position of \r should be consed. *)
|
||||||
in
|
if pos = 0 then
|
||||||
if chr = #"\n" then
|
Vector.fromList (0 :: acc)
|
||||||
(* Is this a \r\n pair? Then the position of \r should be consed. *)
|
|
||||||
if pos = 0 then
|
|
||||||
Vector.fromList (0 :: acc)
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val prevChar = String.sub (str, pos - 1)
|
|
||||||
in
|
|
||||||
if prevChar = #"\r" then
|
|
||||||
helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str)
|
|
||||||
else
|
|
||||||
helpCountLineBreaks (pos - 2, pos :: acc, str)
|
|
||||||
end
|
|
||||||
else if chr = #"\r" then
|
|
||||||
helpCountLineBreaks (pos - 1, pos :: acc, str)
|
|
||||||
else
|
else
|
||||||
helpCountLineBreaks (pos - 1, acc, str)
|
let
|
||||||
end
|
val prevChar = String.sub (str, pos - 1)
|
||||||
end
|
in
|
||||||
|
if prevChar = #"\r" then
|
||||||
|
helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str)
|
||||||
|
else
|
||||||
|
helpCountLineBreaks (pos - 2, pos :: acc, str)
|
||||||
|
end
|
||||||
|
else if chr = #"\r" then
|
||||||
|
helpCountLineBreaks (pos - 1, pos :: acc, str)
|
||||||
|
else
|
||||||
|
helpCountLineBreaks (pos - 1, acc, str)
|
||||||
|
end
|
||||||
in
|
in
|
||||||
fun countLineBreaks str =
|
fun countLineBreaks str =
|
||||||
helpCountLineBreaks (String.size str - 1, [], str)
|
helpCountLineBreaks (String.size str - 1, [], str)
|
||||||
@@ -45,6 +41,42 @@ struct
|
|||||||
, rightLines: int vector list
|
, rightLines: int vector list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local
|
||||||
|
fun goToStart (leftStrings, leftLines, accStrings, accLines) =
|
||||||
|
case (leftStrings, leftLines) of
|
||||||
|
(lsHd :: lsTl, llHd :: llTl) =>
|
||||||
|
goToStart (lsTl, llTl, lsHd :: accStrings, llHd :: accLines)
|
||||||
|
| (_, _) => (accStrings, accLines)
|
||||||
|
|
||||||
|
fun verifyLineList (strings, lines) =
|
||||||
|
case (strings, lines) of
|
||||||
|
(strHd :: strTl, lHd :: lTl) =>
|
||||||
|
let
|
||||||
|
val checkLines = countLineBreaks strHd
|
||||||
|
in
|
||||||
|
if checkLines = lHd then
|
||||||
|
verifyLineList (strTl, lTl)
|
||||||
|
else
|
||||||
|
let val _ = print "line metadata is incorrect\n"
|
||||||
|
in raise Empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
| (_, _) => print "verified lines; no problems\n"
|
||||||
|
in
|
||||||
|
fun verifyLines (buffer: t) =
|
||||||
|
let
|
||||||
|
val (strings, lines) =
|
||||||
|
goToStart
|
||||||
|
( #leftStrings buffer
|
||||||
|
, #leftLines buffer
|
||||||
|
, #rightStrings buffer
|
||||||
|
, #rightLines buffer
|
||||||
|
)
|
||||||
|
in
|
||||||
|
verifyLineList (strings, lines)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
val stringLimit = 1024
|
val stringLimit = 1024
|
||||||
val vecLimit = 32
|
val vecLimit = 32
|
||||||
|
|
||||||
@@ -97,7 +129,7 @@ struct
|
|||||||
in
|
in
|
||||||
fun binSearch (findNum, lines) =
|
fun binSearch (findNum, lines) =
|
||||||
if Vector.length lines = 0 then 0
|
if Vector.length lines = 0 then 0
|
||||||
else helpBinSearch (findNum, lines, 0, Vector.length lines)
|
else helpBinSearch (findNum, lines, 0, Vector.length lines - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun insWhenIdxAndCurIdxAreEqual
|
fun insWhenIdxAndCurIdxAreEqual
|
||||||
@@ -575,7 +607,7 @@ struct
|
|||||||
val newLeftLinesHd =
|
val newLeftLinesHd =
|
||||||
Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
|
Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
|
||||||
if idx < midpoint then Vector.sub (rightLinesHd, idx)
|
if idx < midpoint then Vector.sub (rightLinesHd, idx)
|
||||||
else Vector.sub (newLines, accessIdx) + String.size strSub1)
|
else Vector.sub (newLines, idx - midpoint) + String.size strSub1)
|
||||||
|
|
||||||
val _ = print "line 584\n"
|
val _ = print "line 584\n"
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
|
|||||||
BIN
tests/compare
BIN
tests/compare
Binary file not shown.
@@ -53,7 +53,8 @@ fun compareTxns arr =
|
|||||||
|
|
||||||
fun main () =
|
fun main () =
|
||||||
let
|
let
|
||||||
val _ = compareTxns SvelteComponent.txns
|
val (rope, gap) = compareTxns SvelteComponent.txns
|
||||||
|
val _ = LineGap.verifyLines gap
|
||||||
(*
|
(*
|
||||||
val _ = compareTxns Rust.txns
|
val _ = compareTxns Rust.txns
|
||||||
val _ = compareTxns Seph.txns
|
val _ = compareTxns Seph.txns
|
||||||
|
|||||||
Reference in New Issue
Block a user