-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
241 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local substitute = require("substitute") | ||
|
||
local function get_buf_lines() | ||
local result = vim.api.nvim_buf_get_lines(0, 0, vim.api.nvim_buf_line_count(0), false) | ||
return result | ||
end | ||
|
||
local function execute_keys(feedkeys) | ||
local keys = vim.api.nvim_replace_termcodes(feedkeys, true, false, true) | ||
vim.api.nvim_feedkeys(keys, "x", false) | ||
end | ||
|
||
describe("Substitute linewise", function() | ||
before_each(function() | ||
substitute.setup() | ||
|
||
local buf = vim.api.nvim_create_buf(false, true) | ||
vim.api.nvim_command("buffer " .. buf) | ||
|
||
vim.keymap.set({ "n", "x" }, "]s", function() | ||
require("substitute").operator({ | ||
wrappers = require("substitute.wrappers").build({ "linewise" }), | ||
}) | ||
end, { noremap = true }) | ||
|
||
vim.keymap.set({ "n", "x" }, "]ss", function() | ||
require("substitute").line({ | ||
wrappers = require("substitute.wrappers").build({ "linewise" }), | ||
}) | ||
end, { noremap = true }) | ||
|
||
vim.api.nvim_buf_set_lines(0, 0, -1, true, { "Lorem", "ipsum", "dolor", "sit", "amet" }) | ||
end) | ||
|
||
it("should substitute linewise", function() | ||
execute_keys("y3l") | ||
execute_keys("jll") | ||
execute_keys("]s2l") | ||
|
||
assert.are.same({ "Lorem", "ip", "Lor", "m", "dolor", "sit", "amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute linewise from linewise", function() | ||
execute_keys("yy") | ||
execute_keys("jll") | ||
execute_keys("]s2l") | ||
|
||
assert.are.same({ "Lorem", "ip", "Lorem", "m", "dolor", "sit", "amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute linewise in visual mode", function() | ||
execute_keys("y3l") | ||
execute_keys("jll") | ||
execute_keys("vl") | ||
execute_keys("]s") | ||
|
||
assert.are.same({ "Lorem", "ip", "Lor", "m", "dolor", "sit", "amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute linewise in line mode", function() | ||
execute_keys("y3l") | ||
execute_keys("jll") | ||
execute_keys("]ss") | ||
|
||
assert.are.same({ "Lorem", "Lor", "dolor", "sit", "amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute linewise at the end of line", function() | ||
execute_keys("y3l") | ||
execute_keys("jll") | ||
execute_keys("]s$") | ||
|
||
assert.are.same({ "Lorem", "ip", "Lor", "dolor", "sit", "amet" }, get_buf_lines()) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
local substitute = require("substitute") | ||
|
||
local function get_buf_lines() | ||
local result = vim.api.nvim_buf_get_lines(0, 0, vim.api.nvim_buf_line_count(0), false) | ||
return result | ||
end | ||
|
||
local function execute_keys(feedkeys) | ||
local keys = vim.api.nvim_replace_termcodes(feedkeys, true, false, true) | ||
vim.api.nvim_feedkeys(keys, "x", false) | ||
end | ||
|
||
local buf = nil | ||
describe("Substitute reindent", function() | ||
before_each(function() | ||
substitute.setup() | ||
|
||
buf = vim.api.nvim_create_buf(false, true) | ||
vim.api.nvim_command("buffer " .. buf) | ||
|
||
vim.keymap.set({ "n", "x" }, "=s", function() | ||
require("substitute").operator({ | ||
wrappers = require("substitute.wrappers").build({ "reindent" }), | ||
}) | ||
end, { noremap = true, buffer = buf }) | ||
|
||
vim.keymap.set({ "n", "x" }, "=ss", function() | ||
require("substitute").line({ | ||
wrappers = require("substitute.wrappers").build({ "reindent" }), | ||
}) | ||
end, { noremap = true, buffer = buf }) | ||
|
||
vim.api.nvim_set_option_value("shiftwidth", 4, { buf = buf }) | ||
end) | ||
|
||
it("should substitute and reindent line", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=s2l") | ||
|
||
assert.are.same({ " Lorem", " ipLorm", " dolor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute and reindent multiple lines", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=s2w") | ||
|
||
assert.are.same({ " Lorem", " ipLor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute line and reindent line", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=ss") | ||
|
||
assert.are.same({ " Lorem", " Lor", " dolor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute lines and reindent lines", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("2=ss") | ||
|
||
assert.are.same({ " Lorem", " Lor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
end) | ||
|
||
describe("Substitute linewise and reindent", function() | ||
before_each(function() | ||
substitute.setup() | ||
|
||
buf = vim.api.nvim_create_buf(false, true) | ||
vim.api.nvim_command("buffer " .. buf) | ||
|
||
vim.keymap.set({ "n", "x" }, "=s", function() | ||
require("substitute").operator({ | ||
wrappers = require("substitute.wrappers").build({ "linewise", "reindent" }), | ||
}) | ||
end, { noremap = true, buffer = buf }) | ||
|
||
vim.keymap.set({ "n", "x" }, "=ss", function() | ||
require("substitute").line({ | ||
wrappers = require("substitute.wrappers").build({ "linewise", "reindent" }), | ||
}) | ||
end, { noremap = true, buffer = buf }) | ||
|
||
vim.api.nvim_set_option_value("shiftwidth", 4, { buf = buf }) | ||
end) | ||
|
||
it("should substitute and reindent line", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=s2l") | ||
|
||
assert.are.same({ " Lorem", " ip", " Lor", " m", " dolor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute and reindent multiple lines", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=s2w") | ||
|
||
assert.are.same({ " Lorem", " ip", " Lor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute line and reindent line", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j") | ||
execute_keys("=ss") | ||
|
||
assert.are.same({ " Lorem", " Lor", " dolor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should substitute lines and reindent lines", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("2=ss") | ||
|
||
assert.are.same({ " Lorem", " Lor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
|
||
it("should reindent until eol", function() | ||
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { " Lorem", "ipsum", " dolor", " sit", " amet" }) | ||
|
||
execute_keys("wy3l") | ||
execute_keys("j0ll") | ||
execute_keys("=s$") | ||
|
||
assert.are.same({ " Lorem", " ip", " Lor", " dolor", " sit", " amet" }, get_buf_lines()) | ||
end) | ||
end) |