summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/destination_engine.lua4
-rw-r--r--tests/run.lua32
2 files changed, 33 insertions, 3 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua
index e039851..eb41d47 100644
--- a/lua/clever_f/destination_engine.lua
+++ b/lua/clever_f/destination_engine.lua
@@ -151,7 +151,6 @@ function DestinationEngine:calculate(view, origin, plan, count, first_move)
local request = calculation_inputs(view, origin, plan, count, first_move)
local current_origin = request.origin
local successful_steps = 0
- local boundary_reached = false
while successful_steps < request.count.value do
local destination = next_destination(
@@ -160,14 +159,13 @@ function DestinationEngine:calculate(view, origin, plan, count, first_move)
till_equality_allowed(request, successful_steps)
)
if destination == nil then
- boundary_reached = true
break
end
current_origin = destination
successful_steps = successful_steps + 1
end
- if not boundary_reached then
+ if successful_steps == request.count.value then
return domain.SearchOutcome.complete(current_origin, successful_steps)
end
return domain.SearchOutcome.boundary_before_any(request.origin)
diff --git a/tests/run.lua b/tests/run.lua
index c6905b5..de0013f 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -2771,6 +2771,38 @@ test("Count calculation stops when its fixed boundary is reached", function()
same(4, visits)
end)
+test("Complete outcomes report the last destination after every count unit", function()
+ local view = text_topology.new({ "ababa" }, "utf-8")
+ local target_match = target_plan.build(target("a"), matching_policy())
+ local engine = destination_engine.new()
+ local forward = motion_plan.build(target_match, "f")
+ local backward = motion_plan.build(target_match, "F")
+
+ local forward_outcome = engine:calculate(
+ view,
+ domain.Position.new(1, 1),
+ forward,
+ domain.Count.new(2),
+ true
+ )
+ same(domain.SearchStatus.COMPLETE, forward_outcome.status)
+ truthy(forward_outcome.complete)
+ same(domain.Position.new(1, 5), forward_outcome.endpoint)
+ same(2, forward_outcome.successful_steps)
+
+ local backward_outcome = engine:calculate(
+ view,
+ forward_outcome.endpoint,
+ backward,
+ 2,
+ false
+ )
+ same(domain.SearchStatus.COMPLETE, backward_outcome.status)
+ truthy(backward_outcome.complete)
+ same(domain.Position.new(1, 1), backward_outcome.endpoint)
+ same(2, backward_outcome.successful_steps)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then