fix failing unit test in search-list.sml/build-search-list.sml: perform bounds checking into array
This commit is contained in:
@@ -27,7 +27,7 @@ struct
|
|||||||
case rightStrings of
|
case rightStrings of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
let
|
let
|
||||||
val strIdx = absIdx - bufferIdx
|
val strIdx = Int.max (0, absIdx - bufferIdx)
|
||||||
in
|
in
|
||||||
if strIdx < String.size hd then
|
if strIdx < String.size hd then
|
||||||
helpNextMatch (strIdx, hd, tl, absIdx, searchString, 0)
|
helpNextMatch (strIdx, hd, tl, absIdx, searchString, 0)
|
||||||
|
|||||||
@@ -226,11 +226,14 @@ struct
|
|||||||
fun goToNum (num, {left, right}: t) =
|
fun goToNum (num, {left, right}: t) =
|
||||||
case right of
|
case right of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
if num >= Vector.sub (hd, 0) then
|
if Vector.length hd > 0 then
|
||||||
(* num is greater or equal to first el on right so go right *)
|
if Vector.sub (hd, 0) >= Vector.sub (hd, 0) then
|
||||||
helpGoToNumRight (num, left, right)
|
(* num is greater or equal to first el on right so go right *)
|
||||||
|
helpGoToNumRight (num, left, right)
|
||||||
|
else
|
||||||
|
(* num is less than first el on right so go left *)
|
||||||
|
helpGoToNumLeft (num, left, right)
|
||||||
else
|
else
|
||||||
(* num is less than first el on right so go left *)
|
|
||||||
helpGoToNumLeft (num, left, right)
|
helpGoToNumLeft (num, left, right)
|
||||||
| [] => helpGoToNumLeft (num, left, right)
|
| [] => helpGoToNumLeft (num, left, right)
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ struct
|
|||||||
let
|
let
|
||||||
val chr = String.sub (str, pos)
|
val chr = String.sub (str, pos)
|
||||||
val app = AppUpdate.update (app, InputMsg.CHAR_EVENT chr)
|
val app = AppUpdate.update (app, InputMsg.CHAR_EVENT chr)
|
||||||
|
handle _ => raise Fail (Int.toString pos)
|
||||||
in
|
in
|
||||||
updateLoop (pos + 1, str, app)
|
updateLoop (pos + 1, str, app)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun updateAppWithChars (historyString, app) =
|
fun applyChars (historyString, app) = updateLoop (0, historyString, app)
|
||||||
updateLoop (0, historyString, app)
|
|
||||||
|
|
||||||
fun appFromText text =
|
fun appFromText text =
|
||||||
let val buffer = LineGap.fromString text
|
let val buffer = LineGap.fromString text
|
||||||
@@ -36,8 +36,19 @@ struct
|
|||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
val initialApp = appFromText initialText
|
||||||
|
|
||||||
val charEventTests = describe "CHAR_EVENT regressions"
|
val charEventTests = describe "CHAR_EVENT regressions"
|
||||||
[test "placeholder" (fn _ => Expect.isTrue true)]
|
[test "SearchList.goToNum vector bounds regression (1)" (fn _ =>
|
||||||
|
let
|
||||||
|
val app = appFromText initialText
|
||||||
|
val history = "G12dk"
|
||||||
|
val history = "100G55dkz33dk"
|
||||||
|
val newApp = applyChars (history, app)
|
||||||
|
in
|
||||||
|
(* just expect that we do not fail or throw an exception *)
|
||||||
|
Expect.isTrue true
|
||||||
|
end)]
|
||||||
|
|
||||||
val tests = [charEventTests]
|
val tests = [charEventTests]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user