Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick test #27

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/nvim_comment.lua
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ function M.operator(mode)
if not mode then
line1 = api.nvim_win_get_cursor(0)[1]
line2 = line1
elseif mode:match("[vV]") then
elseif mode:match("[vV]") then
line1 = api.nvim_buf_get_mark(0, "<")[1]
line2 = api.nvim_buf_get_mark(0, ">")[1]
else
44 changes: 39 additions & 5 deletions tests/comment_spec.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
local function setUpBuffer(input, filetype)
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, 'filetype', filetype)
vim.api.nvim_command("sbuffer " .. buf)
vim.api.nvim_command("buffer " .. buf)

vim.api.nvim_buf_set_lines(0, 0, -1, true, vim.split(input, "\n"))
end

local function goToLineRunReturn(line, feedkeys)
local function goToLineRunKeys(line, feedkeys)
vim.api.nvim_win_set_cursor(0, {line,0})
vim.api.nvim_feedkeys(feedkeys, "x", false)

local keys = vim.api.nvim_replace_termcodes(feedkeys, true, false, true)
vim.api.nvim_feedkeys(keys, "x", false)
end
local function getBufLines()
local result = vim.api.nvim_buf_get_lines(
0, 0, vim.api.nvim_buf_line_count(0), false
)
return result
end

local function runCommandAndAssert(line, feedkeys, expected)
local result = goToLineRunReturn(line, feedkeys)
goToLineRunKeys(line, feedkeys)
local result = getBufLines()
assert.are.same(vim.split(expected, "\n"), result)
end

@@ -277,3 +280,34 @@ end]]
end)
end)

describe('issues', function()

before_each(function()
local testModule = require('nvim_comment')
testModule.setup({
marker_padding = true
})
end)

it("issue 22", function()
local input = [[
local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
]]
local expected = [[
-- local foo = 'foo'
-- local bar = 'bar'
-- local baz = 'baz'
local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
]]

setUpBuffer(input, "lua")
runCommandAndAssert(1, "gg0<c-v>jjgc", expected)
end)
end)