summaryrefslogtreecommitdiff
path: root/tests/run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run.lua')
-rw-r--r--tests/run.lua76
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/run.lua b/tests/run.lua
index 3c5150a..31c223e 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -4782,6 +4782,80 @@ test("Direct preview counters ignore Migemo and symbol merging", function()
same(nil, grouping.chars_match_any_signs)
end)
+test("Direct previews return unique valid multibyte byte positions", function()
+ local line = "x\227\129\130x\227\129\132x"
+ local view = text_topology.new({ line }, "utf-8")
+ local planner = direct_preview_planner.new()
+
+ local forward = planner:plan(view, domain.Position.new(1, 1), "f", nil)
+ local backward = planner:plan(view, domain.Position.new(1, 9), "F", nil)
+ local function assert_columns(expected, positions)
+ same(#expected, #positions)
+ local seen = {}
+ for index, position in ipairs(positions) do
+ same(expected[index], position.byte_column)
+ truthy(view:is_character_start(position))
+ falsy(seen[position.byte_column])
+ seen[position.byte_column] = true
+ end
+ end
+ assert_columns({ 2, 5, 6 }, forward)
+ assert_columns({ 6, 5, 2 }, backward)
+
+ local empty_view = text_topology.new({ "" }, "utf-8")
+ same(
+ 0,
+ #planner:plan(empty_view, domain.Position.new(1, 1), "f", nil)
+ )
+ fails(function()
+ direct_preview_planner.validate_marker_positions(view, {
+ domain.Position.new(1, 3),
+ })
+ end, "start an editor character")
+ fails(function()
+ direct_preview_planner.validate_marker_positions(view, {
+ domain.Position.new(1, 2),
+ domain.Position.new(1, 2),
+ })
+ end, "must be unique")
+end)
+
+test("Feedback creates one ordinary direct marker set", function()
+ local state, transitions = fresh_sequence_state()
+ local host = MemoryHost.new({
+ configuration = { mark_direct = true },
+ })
+ local feedback = feedback_service.new({
+ host = host,
+ transitions = transitions,
+ })
+ local positions = {
+ domain.Position.new(1, 2),
+ domain.Position.new(1, 5),
+ domain.Position.new(1, 6),
+ }
+
+ local marker = feedback:create_direct_markers(positions, "window-1")
+ local highlight = host:highlights()[marker.identity]
+ same("CleverFDirect", highlight.group)
+ same(feedback_service.Priority.ORDINARY, highlight.priority)
+ same(3, #highlight.positions)
+ for index = 1, #positions do
+ same(positions[index], highlight.positions[index])
+ end
+ same(marker.identity, state:temporary_overlay_identities()[1])
+ truthy(feedback:remove_temporary_overlay(marker))
+ same(0, #state:temporary_overlay_identities())
+ same(nil, feedback:create_direct_markers({}, "window-1"))
+
+ local evaluation = feedback:evaluate_highlights()
+ same("fallback", evaluation.default_label.source)
+ same(
+ "CleverFDefaultLabel",
+ evaluation.feature_links.CleverFDirect.target
+ )
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then
@@ -4791,4 +4865,4 @@ for _, item in ipairs(tests) do
passed = passed + 1
end
-io.stdout:write(string.format("Phase 10: %d tests passed\n", passed))
+io.stdout:write(string.format("Phase 11: %d tests passed\n", passed))