summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run.lua86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/run.lua b/tests/run.lua
index d4535ef..fb84dd3 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -417,6 +417,92 @@ test("Host adapter connects motion endpoints and dot payloads", function()
same(3, replayed_count.value)
end)
+test("Host adapter bridges native dot to resolved payload replay", function()
+ local mappings = {}
+ local deleted = {}
+ local restored
+ local ownership_autocmd
+ local fed
+ local runtime = {
+ api = {
+ nvim_create_augroup = function()
+ return 9
+ end,
+ nvim_create_autocmd = function(_, options)
+ ownership_autocmd = options.callback
+ return 12
+ end,
+ nvim_feedkeys = function(keys, mode, escape_csi)
+ fed = { keys = keys, mode = mode, escape_csi = escape_csi }
+ end,
+ },
+ fn = {
+ exists = function(name)
+ same("##CmdAtom", name)
+ return 1
+ end,
+ maparg = function(lhs, mode, abbreviation, dictionary)
+ same(".", lhs)
+ same("n", mode)
+ falsy(abbreviation)
+ truthy(dictionary)
+ return { lhs = ".", rhs = "prior-dot" }
+ end,
+ mapset = function(mode, abbreviation, mapping)
+ restored = { mode = mode, abbreviation = abbreviation, mapping = mapping }
+ end,
+ },
+ keymap = {
+ set = function(mode, lhs, callback, options)
+ mappings[mode .. "\0" .. lhs] = {
+ callback = callback,
+ options = options,
+ }
+ end,
+ del = function(mode, lhs)
+ deleted[#deleted + 1] = mode .. "\0" .. lhs
+ mappings[mode .. "\0" .. lhs] = nil
+ end,
+ },
+ keycode = function(keys)
+ return keys
+ end,
+ v = { operator = "d", count = 2, count1 = 2 },
+ }
+ local adapter = host_adapter.new({ runtime = runtime })
+ local payload = domain.DotPayload.new(
+ "f",
+ domain.TargetValue.character("e", string.byte("e"))
+ )
+ local replayed
+ adapter:register_dot_repeat(payload, function(value, count)
+ replayed = { payload = value, count = count }
+ return domain.ActionOutcome.neutral(domain.Position.new(1, 1))
+ end)
+
+ local dot = mappings["n\0."]
+ local motion = mappings["o\0<Plug>(clever-f-dot-motion)"]
+ truthy(dot ~= nil)
+ truthy(motion ~= nil)
+ dot.callback()
+ same("2d<Plug>(clever-f-dot-motion)", fed.keys)
+ same("n", fed.mode)
+ falsy(fed.escape_csi)
+
+ motion.callback()
+ same(payload, replayed.payload)
+ same(2, replayed.count.value)
+
+ ownership_autocmd({ data = { changed = true } })
+ truthy(mappings["n\0."] ~= nil)
+ ownership_autocmd({ data = { changed = true } })
+ same(nil, mappings["n\0."])
+ list_same({ "n\0." }, deleted)
+ same("n", restored.mode)
+ falsy(restored.abbreviation)
+ same("prior-dot", restored.mapping.rhs)
+end)
+
test("Host adapter reads encoding and uses Nvim case conversion", function()
local lowered = {}
local runtime = {