mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
feat(lua): vim.pos/vim.range
This commit is contained in:
63
test/functional/lua/range_spec.lua
Normal file
63
test/functional/lua/range_spec.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
-- Test suite for vim.range
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
local eq = t.eq
|
||||
|
||||
local clear = n.clear
|
||||
local exec_lua = n.exec_lua
|
||||
|
||||
describe('vim.range', function()
|
||||
before_each(clear)
|
||||
after_each(clear)
|
||||
|
||||
it('creates a range with or without optional fields', function()
|
||||
local range = exec_lua(function()
|
||||
return vim.range(3, 5, 4, 6)
|
||||
end)
|
||||
eq(3, range.start.row)
|
||||
eq(5, range.start.col)
|
||||
eq(4, range.end_.row)
|
||||
eq(6, range.end_.col)
|
||||
eq(nil, range.start.buf)
|
||||
eq(nil, range.end_.buf)
|
||||
local buf = exec_lua(function()
|
||||
return vim.api.nvim_create_buf(false, true)
|
||||
end)
|
||||
range = exec_lua(function()
|
||||
return vim.range(3, 5, 4, 6, { buf = buf })
|
||||
end)
|
||||
eq(buf, range.start.buf)
|
||||
eq(buf, range.end_.buf)
|
||||
end)
|
||||
|
||||
it('create a range from two positions when optional fields are not matched', function()
|
||||
local range = exec_lua(function()
|
||||
return vim.range(vim.pos(3, 5), vim.pos(4, 6))
|
||||
end)
|
||||
eq(3, range.start.row)
|
||||
eq(5, range.start.col)
|
||||
eq(4, range.end_.row)
|
||||
eq(6, range.end_.col)
|
||||
eq(nil, range.start.buf)
|
||||
eq(nil, range.end_.buf)
|
||||
|
||||
local buf1 = exec_lua(function()
|
||||
return vim.api.nvim_create_buf(false, true)
|
||||
end)
|
||||
range = exec_lua(function()
|
||||
return vim.range(vim.pos(3, 5, { buf = buf1 }), vim.pos(4, 6, { buf = buf1 }))
|
||||
end)
|
||||
eq(buf1, range.start.buf)
|
||||
eq(buf1, range.end_.buf)
|
||||
|
||||
local buf2 = exec_lua(function()
|
||||
return vim.api.nvim_create_buf(false, true)
|
||||
end)
|
||||
local success = exec_lua(function()
|
||||
return pcall(function()
|
||||
return vim.range(vim.pos(3, 5, { buf = buf1 }), vim.pos(4, 6, { buf = buf2 }))
|
||||
end)
|
||||
end)
|
||||
eq(success, false)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user