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
, windowHeight
, msgs
, visualScrollColumn
, cursorIdx = _
} = app
in
@@ -27,6 +28,7 @@ struct
, windowWidth = windowWidth
, windowHeight = windowHeight
, msgs = msgs
, visualScrollColumn = visualScrollColumn
, cursorIdx = newIdx
}
end

View File

@@ -3,11 +3,12 @@ $(SML_LIB)/basis/basis.mlb
(* LIBRARIES *)
lib/brolib-sml/src/line_gap.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 *)
message-types/input-msg.sml
message-types/draw-msg.sml
message-types/search-msg.sml
message-types/mailbox-type.sml
ann
@@ -29,16 +30,21 @@ fcore/text-constants.sml
ann
"allowVectorExps true"
in
fcore/rect.sml
fcore/pipe-cursor.sml
fcore/text-builder.sml
fcore/cursor-dfa/make-dfa-loop.sml
fcore/cursor-dfa/vi-word-dfa.sml
fcore/cursor-dfa/vi-caps-word-dfa.sml
fcore/cursor-dfa/vi-dlr-dfa.sml
fcore/rect.sml
fcore/pipe-cursor.sml
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/text-window.sml
fcore/text-scroll.sml
fcore/normal-mode/normal-finish.sml
fcore/normal-mode/normal-search-finish.sml

View File

@@ -4,47 +4,6 @@ struct
open Railroad.Test
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) =
let
val {cursorIdx, buffer, ...} = app
@@ -68,20 +27,6 @@ struct
(* assert *)
Expect.isTrue (cursorIdx = 0)
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 _ =>
let
(* arrange *)
@@ -103,20 +48,6 @@ struct
val app = TestUtils.init buffer
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 *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"h")
in
@@ -135,20 +66,6 @@ struct
val app = TestUtils.init buffer
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 *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in
@@ -177,20 +94,6 @@ struct
val app = TestUtils.init buffer
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 *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
in
@@ -216,26 +119,6 @@ struct
val app2 = TestUtils.update (app1, 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 *)
val c1 = getChr app1 = #"w"
val c2 = getChr app2 = #"g"
@@ -256,27 +139,6 @@ struct
val app2 = TestUtils.update (app1, 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 *)
val c1 = getChr app1 = #"o"
val c2 = getChr app2 = #"y"
@@ -297,27 +159,6 @@ struct
val app2 = TestUtils.update (app1, 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 *)
val c1 = getChr app1 = #"r"
val c2 = getChr app2 = #"e"
@@ -404,25 +245,6 @@ struct
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 *)
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 contiguous string when column = 1"
(fn _ =>
let
@@ -443,25 +265,6 @@ struct
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 *)
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 contiguous string when column = 2"
(fn _ =>
let
@@ -482,25 +285,6 @@ struct
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 *)
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
"skips '\\n' when cursor is on '\\n',\
\prev-char is '\\n' and prev-prev char is not '\\n'"
@@ -568,20 +352,6 @@ struct
(* act *)
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 *)
val chr = String.sub ("hello world", cursorIdx)
in
@@ -718,20 +488,6 @@ struct
(* act *)
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 *)
val chr = String.sub ("hello world", cursorIdx)
in
@@ -833,22 +589,6 @@ struct
Expect.isTrue (getChr app = #"o")
end)
, 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\
\when in punctuation word and there is at least one\
\punctuation char after cursor"
@@ -865,22 +605,6 @@ struct
Expect.isTrue (getChr app = #"^")
end)
, 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,\
\when cursor is on last char of current word"
(fn _ =>
@@ -1017,18 +741,6 @@ struct
(* 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 *)
val app = TestUtils.update (app, CHAR_EVENT #"E")
in
(* assert *)
Expect.isTrue (getChr app = #"o")
end)
, test
"moves cursor to last char of next WORD,\
\when cursor is on last char of current WORD"
@@ -1326,19 +1038,6 @@ struct
val app = TestUtils.init buffer
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 *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"0")
in
@@ -1386,27 +1085,6 @@ struct
(* act *)
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 *)
val chr = getChr app
in
@@ -1422,18 +1100,6 @@ struct
val buffer = LineGap.fromString "hello wor9\n"
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 *)
val app = TestUtils.update (app, CHAR_EVENT #"$")
in
@@ -1455,27 +1121,6 @@ struct
val app = TestUtils.update (app, CHAR_EVENT #"$")
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 = Char.toString nchr ^ "\n"
in