diff options
| -rw-r--r-- | lua/clever_f/sequence_coordinator.lua | 13 | ||||
| -rw-r--r-- | tests/run.lua | 41 |
2 files changed, 53 insertions, 1 deletions
diff --git a/lua/clever_f/sequence_coordinator.lua b/lua/clever_f/sequence_coordinator.lua index d391eec..37657b2 100644 --- a/lua/clever_f/sequence_coordinator.lua +++ b/lua/clever_f/sequence_coordinator.lua @@ -204,6 +204,17 @@ function SequenceCoordinator:acquire_primary(descriptor, invocation) ) end +function SequenceCoordinator:resolve_acquisition(descriptor, invocation) + local result = self:acquire_primary(descriptor, invocation) + if type(result.has_outcome) ~= "function" then + fail("AcquisitionService must return an AcquisitionResult", 2) + end + if result:has_outcome() then + return result.outcome + end + return result +end + function SequenceCoordinator:primary(value) local descriptor = self:validate_primary_descriptor(value) local invocation = self:read_primary_invocation() @@ -214,7 +225,7 @@ function SequenceCoordinator:primary(value) ) invocation.repeat_decision = self:decide_primary(invocation) if invocation.repeat_decision == repeat_resolver_factory.Decision.ACQUIRE then - return self:acquire_primary(descriptor, invocation) + return self:resolve_acquisition(descriptor, invocation) end return descriptor end diff --git a/tests/run.lua b/tests/run.lua index f004a23..0b83ef1 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -7223,6 +7223,47 @@ test("Acquiring primary coordination passes the pressed descriptor", function() same("a", result.target.value) end) +test("Primary coordination stops on each acquisition outcome", function() + local cases = { + { + packet = { kind = "special_key", name = "Escape", bytes = { 27 } }, + kind = domain.ActionKind.ESCAPE, + }, + { + packet = { kind = "text", text = "\r" }, + kind = domain.ActionKind.EMPTY, + diagnostic = acquisition_service.PREVIOUS_INPUT_NOT_FOUND, + }, + { + packet = { kind = "error", message = "input unavailable" }, + kind = domain.ActionKind.ERROR, + diagnostic = "input unavailable", + }, + } + + for _, case in ipairs(cases) do + fresh_sequence_state() + local origin = domain.Position.new(1, 1) + local host = MemoryHost.new({ + buffer_lines = { "aba" }, + cursor = origin, + input_packets = { case.packet }, + configuration = { + mark_cursor = false, + mark_char = false, + }, + }) + local outcome = sequence_coordinator.new({ host = host }):primary("f") + truthy(domain.ActionOutcome.is(outcome)) + same(case.kind, outcome.kind) + same(origin, outcome.position) + same(origin, host:read_cursor()) + if case.diagnostic ~= nil then + same(case.diagnostic, host:diagnostics()[1].text) + end + end +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
