copy new file order from shf.mlb to shf-tests.mlb, and remove split-string tests because we have tried to refactor string-search logic to be separate from the data structure

This commit is contained in:
2025-09-16 01:25:27 +01:00
parent 873fa1b1ac
commit 820a6c2462
3 changed files with 13 additions and 360 deletions

View File

@@ -15,6 +15,7 @@ struct
, windowWidth , windowWidth
, windowHeight , windowHeight
, msgs , msgs
, visualScrollColumn
, cursorIdx = _ , cursorIdx = _
} = app } = app
in in
@@ -27,6 +28,7 @@ struct
, windowWidth = windowWidth , windowWidth = windowWidth
, windowHeight = windowHeight , windowHeight = windowHeight
, msgs = msgs , msgs = msgs
, visualScrollColumn = visualScrollColumn
, cursorIdx = newIdx , cursorIdx = newIdx
} }
end end

View File

@@ -3,11 +3,12 @@ $(SML_LIB)/basis/basis.mlb
(* LIBRARIES *) (* LIBRARIES *)
lib/brolib-sml/src/line_gap.sml lib/brolib-sml/src/line_gap.sml
lib/brolib-sml/src/gap_set.sml lib/brolib-sml/src/gap_set.sml
lib/cozette-sml/fonts/cozette-ascii.mlb lib/cozette-sml/fonts-with-z-index/cozette-ascii.mlb
(* FUNCTIONAL CORE *) (* FUNCTIONAL CORE *)
message-types/input-msg.sml message-types/input-msg.sml
message-types/draw-msg.sml message-types/draw-msg.sml
message-types/search-msg.sml
message-types/mailbox-type.sml message-types/mailbox-type.sml
ann ann
@@ -29,16 +30,21 @@ fcore/text-constants.sml
ann ann
"allowVectorExps true" "allowVectorExps true"
in in
fcore/rect.sml
fcore/pipe-cursor.sml
fcore/text-builder.sml
fcore/cursor-dfa/make-dfa-loop.sml fcore/cursor-dfa/make-dfa-loop.sml
fcore/cursor-dfa/vi-word-dfa.sml fcore/cursor-dfa/vi-word-dfa.sml
fcore/cursor-dfa/vi-caps-word-dfa.sml fcore/cursor-dfa/vi-caps-word-dfa.sml
fcore/cursor-dfa/vi-dlr-dfa.sml fcore/cursor-dfa/vi-dlr-dfa.sml
fcore/rect.sml
fcore/pipe-cursor.sml
end end
fcore/text-builder/text-builder-utils.sml
fcore/text-builder/text-builder-with-cursor.sml
fcore/text-builder/text-builder-with-highlight.sml
fcore/text-builder/normal-mode-text-builder.sml
fcore/text-builder/search-bar.sml
fcore/cursor.sml fcore/cursor.sml
fcore/text-window.sml fcore/text-scroll.sml
fcore/normal-mode/normal-finish.sml fcore/normal-mode/normal-finish.sml
fcore/normal-mode/normal-search-finish.sml fcore/normal-mode/normal-search-finish.sml

View File

@@ -4,47 +4,6 @@ struct
open Railroad.Test open Railroad.Test
open InputMsg open InputMsg
local
fun helpCountLineBreaks (pos, acc, str) =
if pos < 0 then
Vector.fromList acc
else
let
val chr = String.sub (str, pos)
in
if chr = #"\n" then
(* 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 - 1, pos :: acc, str)
end
else if chr = #"\r" then
helpCountLineBreaks (pos - 1, pos :: acc, str)
else
helpCountLineBreaks (pos - 1, acc, str)
end
fun countLineBreaks str =
helpCountLineBreaks (String.size str - 1, [], str)
in
(* creates a LineGap.t with valid metadata from a list of strings *)
fun fromList lst =
{ idx = 0
, line = 0
, leftStrings = []
, leftLines = []
, rightStrings = lst
, rightLines = List.map countLineBreaks lst
}
end
fun getChr (app: AppType.app_type) = fun getChr (app: AppType.app_type) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -68,20 +27,6 @@ struct
(* assert *) (* assert *)
Expect.isTrue (cursorIdx = 0) Expect.isTrue (cursorIdx = 0)
end) end)
, test "moves cursor left by one in split string when cursorIdx > 0"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hello", " world"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 5)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"h")
in
(* assert *)
Expect.isTrue (cursorIdx = 4)
end)
, test "does not move cursor when cursorIdx = 0" (fn _ => , test "does not move cursor when cursorIdx = 0" (fn _ =>
let let
(* arrange *) (* arrange *)
@@ -103,20 +48,6 @@ struct
val app = TestUtils.init buffer val app = TestUtils.init buffer
val app = AppWith.idx (app, 6) val app = AppWith.idx (app, 6)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"h")
in
(* assert *)
Expect.isTrue (cursorIdx = 4)
end)
, test "moves cursor left by two in split string when prev chr is \\n"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hello\n", " world"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 6)
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"h") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"h")
in in
@@ -135,20 +66,6 @@ struct
val app = TestUtils.init buffer val app = TestUtils.init buffer
val {cursorIdx = oldCursorIdx, ...} = app val {cursorIdx = oldCursorIdx, ...} = app
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in
(* assert *)
Expect.isTrue (oldCursorIdx = 0 andalso cursorIdx = 1)
end)
, test "moves cursor right by one in split string when cursorIdx < length"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hello ", "world"]
val app = TestUtils.init buffer
val {cursorIdx = oldCursorIdx, ...} = app
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in in
@@ -177,20 +94,6 @@ struct
val app = TestUtils.init buffer val app = TestUtils.init buffer
val app = AppWith.idx (app, 4) val app = AppWith.idx (app, 4)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in
(* assert *)
Expect.isTrue (cursorIdx = 6)
end)
, test "moves right by two in split string when char is followed by \\n"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hello\n", "world"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 4)
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in in
@@ -216,26 +119,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"j") val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j") val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *)
val c1 = getChr app1 = #"w"
val c2 = getChr app2 = #"g"
val c3 = getChr app3 = #"q"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur down one column in split string when column = 0"
(fn _ =>
let
(* arrange *)
val buffer =
fromList ["hello \n", "world \n", "goodbye \n", "qorld"]
val app = TestUtils.init buffer
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"j")
val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *) (* assert *)
val c1 = getChr app1 = #"w" val c1 = getChr app1 = #"w"
val c2 = getChr app2 = #"g" val c2 = getChr app2 = #"g"
@@ -256,27 +139,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"j") val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j") val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *)
val c1 = getChr app1 = #"o"
val c2 = getChr app2 = #"y"
val c3 = getChr app3 = #"r"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur down one column in split string when column = 1"
(fn _ =>
let
(* arrange *)
val buffer =
fromList ["hello \n", "world ", "\nb", "ye \nfriends \n"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 1)
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"j")
val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *) (* assert *)
val c1 = getChr app1 = #"o" val c1 = getChr app1 = #"o"
val c2 = getChr app2 = #"y" val c2 = getChr app2 = #"y"
@@ -297,27 +159,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"j") val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j") val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *)
val c1 = getChr app1 = #"r"
val c2 = getChr app2 = #"e"
val c3 = getChr app3 = #"i"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur down one column in split string when column = 2"
(fn _ =>
let
(* arrange *)
val buffer =
fromList ["hello \n", "world ", "\nb", "ye \nfriends \n"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 2)
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"j")
val app2 = TestUtils.update (app1, CHAR_EVENT #"j")
val app3 = TestUtils.update (app2, CHAR_EVENT #"j")
(* assert *) (* assert *)
val c1 = getChr app1 = #"r" val c1 = getChr app1 = #"r"
val c2 = getChr app2 = #"e" val c2 = getChr app2 = #"e"
@@ -397,25 +238,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"k") val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k") val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *)
val c1 = getChr app1 = #"9"
val c2 = getChr app2 = #"4"
val c3 = getChr app3 = #"0"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur up one column in split string when column = 0" (fn _ =>
let
(* arrange *)
val buffer = fromList ["0__", "\n4__", "_\n9_", "__\n14_"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 14)
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"k")
val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *) (* assert *)
val c1 = getChr app1 = #"9" val c1 = getChr app1 = #"9"
val c2 = getChr app2 = #"4" val c2 = getChr app2 = #"4"
@@ -436,25 +258,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"k") val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k") val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *)
val c1 = getChr app1 = #"1"
val c2 = getChr app2 = #"5"
val c3 = getChr app3 = #"w"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur up one column in split string when column = 1" (fn _ =>
let
(* arrange *)
val buffer = fromList ["_w_\n", "_5__", "\n_10_\n", "_15"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 15)
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"k")
val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *) (* assert *)
val c1 = getChr app1 = #"1" val c1 = getChr app1 = #"1"
val c2 = getChr app2 = #"5" val c2 = getChr app2 = #"5"
@@ -475,25 +278,6 @@ struct
val app2 = TestUtils.update (app1, CHAR_EVENT #"k") val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k") val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *)
val c1 = getChr app1 = #"1"
val c2 = getChr app2 = #"6"
val c3 = getChr app3 = #"2"
in
Expect.isTrue (c1 andalso c2 andalso c3)
end)
, test "moves cursur up one column in split string when column = 2" (fn _ =>
let
(* arrange *)
val buffer = fromList ["__", "2\n", "__6", "\n__10", "\n__1", "5\n"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 15)
(* act *)
val app1 = TestUtils.update (app, CHAR_EVENT #"k")
val app2 = TestUtils.update (app1, CHAR_EVENT #"k")
val app3 = TestUtils.update (app2, CHAR_EVENT #"k")
(* assert *) (* assert *)
val c1 = getChr app1 = #"1" val c1 = getChr app1 = #"1"
val c2 = getChr app2 = #"6" val c2 = getChr app2 = #"6"
@@ -568,20 +352,6 @@ struct
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"w") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"w")
(* assert *)
val chr = String.sub ("hello world", cursorIdx)
in
Expect.isTrue (chr = #"w")
end)
, test "moves cursor to start of next word in split string" (fn _ =>
let
(* arrange *)
val buffer = fromList ["hello ", "world"]
val app = TestUtils.init buffer
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"w")
(* assert *) (* assert *)
val chr = String.sub ("hello world", cursorIdx) val chr = String.sub ("hello world", cursorIdx)
in in
@@ -718,20 +488,6 @@ struct
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"W") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"W")
(* assert *)
val chr = String.sub ("hello world", cursorIdx)
in
Expect.isTrue (chr = #"w")
end)
, test "moves cursor to start of next WORD in split string" (fn _ =>
let
(* arrange *)
val buffer = fromList ["hello ", "world"]
val app = TestUtils.init buffer
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"W")
(* assert *) (* assert *)
val chr = String.sub ("hello world", cursorIdx) val chr = String.sub ("hello world", cursorIdx)
in in
@@ -833,22 +589,6 @@ struct
Expect.isTrue (getChr app = #"o") Expect.isTrue (getChr app = #"o")
end) end)
, test , test
"moves cursor to last alphanumeric char in split string\
\when in alphanumeric word and there is at least one\
\alphanumeric char after cursor"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hello ", "world", "\n"]
val app = TestUtils.init buffer
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"e")
in
(* assert *)
Expect.isTrue (getChr app = #"o")
end)
, test
"moves cursor to last punctuation char in contiguous string\ "moves cursor to last punctuation char in contiguous string\
\when in punctuation word and there is at least one\ \when in punctuation word and there is at least one\
\punctuation char after cursor" \punctuation char after cursor"
@@ -865,22 +605,6 @@ struct
Expect.isTrue (getChr app = #"^") Expect.isTrue (getChr app = #"^")
end) end)
, test , test
"moves cursor to last punctuation char in split string\
\when in punctuation word and there is at least one\
\punctuation char after cursor"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["#$", "%!^ ", "world", "\n"]
val app = TestUtils.init buffer
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"e")
in
(* assert *)
Expect.isTrue (getChr app = #"^")
end)
, test
"moves cursor to last char of next word,\ "moves cursor to last char of next word,\
\when cursor is on last char of current word" \when cursor is on last char of current word"
(fn _ => (fn _ =>
@@ -1011,18 +735,6 @@ struct
val buffer = LineGap.fromString "hel!!!lo world\n" val buffer = LineGap.fromString "hel!!!lo world\n"
val app = TestUtils.init buffer val app = TestUtils.init buffer
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"E")
in
(* assert *)
Expect.isTrue (getChr app = #"o")
end)
, test "moves cursor to last char in WORD when in split string" (fn _ =>
let
(* arrange *)
val buffer = fromList ["hel", "!!!", "lo ", "world", "\n"]
val app = TestUtils.init buffer
(* act *) (* act *)
val app = TestUtils.update (app, CHAR_EVENT #"E") val app = TestUtils.update (app, CHAR_EVENT #"E")
in in
@@ -1326,19 +1038,6 @@ struct
val app = TestUtils.init buffer val app = TestUtils.init buffer
val app = AppWith.idx (app, 7) val app = AppWith.idx (app, 7)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"0")
in
(* assert *)
Expect.isTrue (cursorIdx = 0)
end)
, test "moves cursor to 0 in split string when on first line" (fn _ =>
let
(* arrange *)
val buffer = fromList ["hel", "lo ", "w7r", "ld\n"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 7)
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"0") val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"0")
in in
@@ -1386,27 +1085,6 @@ struct
(* act *) (* act *)
val app = TestUtils.update (app, CHAR_EVENT #"0") val app = TestUtils.update (app, CHAR_EVENT #"0")
(* assert *)
val chr = getChr app
in
(* assert *)
Expect.isTrue (chr = #"#")
end)
, test
"moves cursor to first char after '\\n' in split string\
\when cursor is after first line"
(fn _ =>
let
(* arrange *)
val buffer = fromList
["hel", "lo ", "wor", "ld\n", "#el", "lo ", "aga", "in\n"]
val buffer = LineGap.fromString "hello world\n#ello again\n"
val app = TestUtils.init buffer
val app = AppWith.idx (app, 21)
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"0")
(* assert *) (* assert *)
val chr = getChr app val chr = getChr app
in in
@@ -1422,18 +1100,6 @@ struct
val buffer = LineGap.fromString "hello wor9\n" val buffer = LineGap.fromString "hello wor9\n"
val app = TestUtils.init buffer val app = TestUtils.init buffer
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"$")
in
(* assert *)
Expect.isTrue (getChr app = #"9")
end)
, test "moves cursor to char before '\\n' in split string" (fn _ =>
let
(* arrange *)
val buffer = fromList ["hel", "lo ", " wor9\n"]
val app = TestUtils.init buffer
(* act *) (* act *)
val app = TestUtils.update (app, CHAR_EVENT #"$") val app = TestUtils.update (app, CHAR_EVENT #"$")
in in
@@ -1455,27 +1121,6 @@ struct
val app = TestUtils.update (app, CHAR_EVENT #"$") val app = TestUtils.update (app, CHAR_EVENT #"$")
val newIdx = #cursorIdx app val newIdx = #cursorIdx app
val nchr = getChr app
val nchr = Char.toString nchr ^ "\n"
in
(* assert *)
Expect.isTrue (oldIdx = newIdx)
end)
, test
"leaves cursor at same idx in split string\
\when char after cursor is '\\n'"
(fn _ =>
let
(* arrange *)
val buffer = fromList ["hel", "lo\n", " wo", "rld", "\n"]
val app = TestUtils.init buffer
val app = AppWith.idx (app, 11)
val oldIdx = #cursorIdx app
(* act *)
val app = TestUtils.update (app, CHAR_EVENT #"$")
val newIdx = #cursorIdx app
val nchr = getChr app val nchr = getChr app
val nchr = Char.toString nchr ^ "\n" val nchr = Char.toString nchr ^ "\n"
in in