aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/ts_utils_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/ts_utils_spec.lua')
-rw-r--r--tests/unit/ts_utils_spec.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/unit/ts_utils_spec.lua b/tests/unit/ts_utils_spec.lua
index 1825a3b68..a3b334413 100644
--- a/tests/unit/ts_utils_spec.lua
+++ b/tests/unit/ts_utils_spec.lua
@@ -39,3 +39,70 @@ describe("is_in_node_range", function()
assert.is_false(test_is_in_node_range(3, 0))
end)
end)
+
+describe("update_selection", function()
+ local function get_updated_selection(case)
+ vim.api.nvim_buf_set_lines(0, 0, -1, false, case.lines)
+ tsutils.update_selection(0, case.node, case.selection_mode)
+ vim.cmd "normal! y"
+ return vim.fn.getreg '"'
+ end
+
+ it("charwise1", function()
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 0, 2, 1 },
+ selection_mode = "v",
+ },
+ "foo\n\nb"
+ )
+ it("charwise2", function() end)
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 1, 2, 1 },
+ selection_mode = "v",
+ },
+ "oo\n\nb"
+ )
+ it("charwise3", function() end)
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 2, 2, 1 },
+ selection_mode = "v",
+ },
+ "o\n\nb"
+ )
+ it("charwise4", function() end)
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 3, 2, 1 },
+ selection_mode = "v",
+ },
+ "\n\nb"
+ )
+ end)
+ it("linewise", function()
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 3, 2, 1 },
+ selection_mode = "V",
+ },
+ "foo\n\nbar\n"
+ )
+ end)
+ it("blockwise", function()
+ assert.equal(
+ get_updated_selection {
+ lines = { "foo", "", "bar" },
+ node = { 0, 3, 2, 1 },
+ selection_mode = "<C-v>",
+ },
+ "foo\n\nbar"
+ )
+ end)
+end)