Skip to content

Commit

Permalink
Add dot repetition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
backdround committed Jan 15, 2024
1 parent 425fb89 commit 7219f63
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions tests/specs/dot-repeat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("dot `.` repeat", function()
assert.buffer("a a w a w a w end")
end)

it("should preserve option after another hop", function()
it("should preserve options after another hop", function()
h.feedkeys("d", false)
h.hop_with_character(ft.hop_forward_to_char, "w")
assert.buffer("a a w a w a w a w end")
Expand All @@ -26,7 +26,7 @@ describe("dot `.` repeat", function()
assert.buffer("a a w a w a w end")
end)

it("should preserve option after user repeat", function()
it("should preserve options after user repeat", function()
h.feedkeys("d", false)
h.hop_with_character(ft.hop_forward_to_char, "w")
assert.buffer("a a w a w a w a w end")
Expand Down Expand Up @@ -64,4 +64,39 @@ describe("dot `.` repeat", function()
h.feedkeys(".", true)
assert.buffer("a | a end")
end)

it("should work with custom-operators", function()
vim.keymap.set("n", "f", ft.hop_forward_to_char)

local start_column = nil
local end_column = nil
local update_operator_area = function()
start_column = vim.api.nvim_buf_get_mark(0, "[")[2] + 1
end_column = vim.api.nvim_buf_get_mark(0, "]")[2] + 1
end

-- selene: allow(global_usage)
_G.Test_operator = update_operator_area
vim.opt.operatorfunc = "v:lua.Test_operator"

vim.api.nvim_feedkeys("g@fw", "nx", false)
assert.are.same(3, start_column)
assert.are.same(7, end_column)

h.set_cursor(1, 7)
vim.api.nvim_feedkeys(".", "nx", false)
assert.are.same(7, start_column)
assert.are.same(11, end_column)
end)

it("should work in macros that uses dot", function()
vim.keymap.set("n", "f", ft.hop_forward_to_char)

vim.api.nvim_feedkeys("dwu", "ntx", true)
vim.fn.setreg("a", ".fw")

vim.api.nvim_feedkeys("@a", "nx", true)
assert.buffer("a a w a w a w a w a w end")
assert.cursor_at(1, 5)
end)
end)

0 comments on commit 7219f63

Please sign in to comment.