Skip to content

Commit

Permalink
comment chunk test/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alex.tylor committed Mar 15, 2022
1 parent 0cd8228 commit 323d8fb
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ However you can pass in some config options, the defaults are:
line_mapping = "gcc",
-- Visual/Operator mapping left hand side
operator_mapping = "gc",
-- text object mapping, comment chunk,,
comment_chunk_text_object = "ic",
-- Hook function to call before commenting takes place
hook = nil
}
Expand Down Expand Up @@ -91,7 +93,7 @@ require('nvim_comment').setup({create_mappings = false})
- Custom mappings

```lua
require('nvim_comment').setup({line_mapping = "<leader>cl", operator_mapping = "<leader>c"})
require('nvim_comment').setup({line_mapping = "<leader>cl", operator_mapping = "<leader>c", comment_chunk_text_object = "ic"})
```

- Disable marker padding
Expand Down
116 changes: 109 additions & 7 deletions tests/comment_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
local function runCommandAndAssert(line, feedkeys, expected)
goToLineRunKeys(line, feedkeys)
local result = getBufLines()
assert.are.same(result, vim.split(expected, "\n"))
assert.are.same(vim.split(expected, "\n"), result)
end

describe("comment/uncomment", function()
Expand Down Expand Up @@ -272,6 +272,108 @@ end]]
end)
end)

describe("comment chunks", function()
before_each(function()
local testModule = require("nvim_comment")
testModule.setup({
marker_padding = true,
comment_empty = true,
})
end)

local input = [[
-- local foo = 'foo'
-- local bar = 'bar'
-- local baz = 'baz'
local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
-- local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
-- local foo = 'foo'
-- local bar = 'bar']]

it("Should handle text obeject at top of buffer", function()
local expected = [[
local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
-- local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
-- local foo = 'foo'
-- local bar = 'bar']]

setUpBuffer(input, "lua")
runCommandAndAssert(1, "gcic", expected)
end)

it("Should handle text obeject at botton of buffer", function()
local expected = [[
-- local foo = 'foo'
-- local bar = 'bar'
-- local baz = 'baz'
local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
-- local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
local foo = 'foo'
local bar = 'bar']]

setUpBuffer(input, "lua")
runCommandAndAssert(1, "Ggcic", expected)
end)

it("Should handle single line text object", function()
local expected = [[
-- local foo = 'foo'
-- local bar = 'bar'
-- local baz = 'baz'
local foo = 'foo'
local baz = 'baz'
local baz = 'baz'
-- local foo = 'foo'
-- local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
-- local foo = 'foo'
-- local bar = 'bar']]

setUpBuffer(input, "lua")
runCommandAndAssert(6, "dic", expected)
end)

it("Should handle multi line text object", function()
local expected = [[
-- local foo = 'foo'
-- local bar = 'bar'
-- local baz = 'baz'
local foo = 'foo'
local baz = 'baz'
-- local foo = 'foo'
local baz = 'baz'
local bar = 'bar'
local baz = 'baz'
-- local foo = 'foo'
-- local bar = 'bar']]

setUpBuffer(input, "lua")
runCommandAndAssert(9, "dic", expected)
end)
end)

describe("issues", function()
before_each(function()
local testModule = require("nvim_comment")
Expand Down Expand Up @@ -312,12 +414,12 @@ this is some block
yeah]]

local expected = [[
-- this is some block
-- of idented text
--
-- with empty lines
-- yeah]]
this is some block
-- of idented text
--
with empty lines
yeah]]
setUpBuffer(input, "lua")
runCommandAndAssert(1, "gg0<c-v>Ggc", expected)
runCommandAndAssert(1, "ggjVjgc", expected)
end)
end)

0 comments on commit 323d8fb

Please sign in to comment.