summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run.lua74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/run.lua b/tests/run.lua
index f9fbeb8..60d6b5b 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -2495,6 +2495,80 @@ test("Forward Visual-exclusive TILL uses target positions", function()
)
end)
+test("MotionPlanFactory limits exclusive policy to character and line Visual", function()
+ local view = text_topology.new({ "axz" }, "utf-8")
+ local origin = domain.Position.new(1, 1)
+ local target_match = target_plan.build(target("x"), matching_policy())
+ local factory = motion_plan.new()
+ local engine = destination_engine.new()
+ local cases = {
+ { "v", domain.EndpointPolicy.VISUAL_EXCLUSIVE },
+ { "V", domain.EndpointPolicy.VISUAL_EXCLUSIVE },
+ { string.char(0x16), domain.EndpointPolicy.REGULAR },
+ { "s", domain.EndpointPolicy.REGULAR },
+ { "S", domain.EndpointPolicy.REGULAR },
+ { string.char(0x13), domain.EndpointPolicy.REGULAR },
+ { "n", domain.EndpointPolicy.REGULAR },
+ { "no", domain.EndpointPolicy.REGULAR },
+ }
+
+ for _, case in ipairs(cases) do
+ local context = domain.ModeContext.from_full_mode(case[1])
+ local kind = context.visual_kind or context.select_kind
+ local selection = kind ~= nil
+ and domain.Selection.active(
+ kind,
+ origin,
+ origin,
+ domain.SelectionOption.EXCLUSIVE
+ )
+ or domain.Selection.inactive(domain.SelectionOption.EXCLUSIVE)
+ local plan = factory:build_for_context(
+ target_match,
+ "f",
+ context,
+ selection,
+ domain.SearchScope.BUFFER
+ )
+ same(case[2], plan.endpoint_policy, case[1])
+ local expected_column = case[2] == domain.EndpointPolicy.VISUAL_EXCLUSIVE
+ and 3
+ or 2
+ same(
+ domain.Position.new(1, expected_column),
+ engine:calculate(view, origin, plan, 1, true).endpoint,
+ case[1]
+ )
+ end
+
+ local inclusive_visual = factory:build_for_context(
+ target_match,
+ "f",
+ "v",
+ domain.SelectionOption.INCLUSIVE,
+ "buffer"
+ )
+ same(domain.EndpointPolicy.REGULAR, inclusive_visual.endpoint_policy)
+
+ local exclusive_backward = factory:build_for_context(
+ target_match,
+ "F",
+ "v",
+ domain.SelectionOption.EXCLUSIVE,
+ "buffer"
+ )
+ same(
+ domain.Position.new(1, 2),
+ engine:calculate(
+ view,
+ domain.Position.new(1, 3),
+ exclusive_backward,
+ 1,
+ true
+ ).endpoint
+ )
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then