aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/extmark_spec.lua63
-rw-r--r--test/functional/helpers.lua10
-rw-r--r--test/functional/lua/treesitter_spec.lua18
-rw-r--r--test/functional/provider/perl_spec.lua50
-rw-r--r--test/functional/ui/bufhl_spec.lua6
5 files changed, 107 insertions, 40 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 602f879ae8..a2a188d036 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -17,17 +17,6 @@ local function expect(contents)
return eq(contents, helpers.curbuf_contents())
end
-local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
- local rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({er, ec}, rv)
- feed("u")
- rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({sr, sc}, rv)
- feed("<c-r>")
- rv = curbufmeths.get_extmark_by_id(ns, mark, false)
- eq({er, ec}, rv)
-end
-
local function set_extmark(ns_id, id, line, col, opts)
if opts == nil then
opts = {}
@@ -42,7 +31,25 @@ local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then
opts = {}
end
- return curbufmeths.get_extmarks(ns_id, start, end_, opts, false)
+ return curbufmeths.get_extmarks(ns_id, start, end_, opts)
+end
+
+local function get_extmark_by_id(ns_id, id, opts)
+ if opts == nil then
+ opts = {}
+ end
+ return curbufmeths.get_extmark_by_id(ns_id, id, opts)
+end
+
+local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
+ local rv = get_extmark_by_id(ns, mark)
+ eq({er, ec}, rv)
+ feed("u")
+ rv = get_extmark_by_id(ns, mark)
+ eq({sr, sc}, rv)
+ feed("<c-r>")
+ rv = get_extmark_by_id(ns, mark)
+ eq({er, ec}, rv)
end
local function batch_set(ns_id, positions)
@@ -96,7 +103,7 @@ describe('API/extmarks', function()
it('adds, updates and deletes marks', function()
local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({positions[1][1], positions[1][2]}, rv)
-- Test adding a second mark on same row works
rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
@@ -105,14 +112,14 @@ describe('API/extmarks', function()
-- Test an update, (same pos)
rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
+ rv = get_extmark_by_id(ns, marks[2])
eq({positions[2][1], positions[2][2]}, rv)
-- Test an update, (new pos)
row = positions[1][1]
col = positions[1][2] + 1
rv = set_extmark(ns, marks[1], row, col)
eq(marks[1], rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({row, col}, rv)
-- remove the test marks
@@ -435,7 +442,7 @@ describe('API/extmarks', function()
~ |
|
]])
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, 6}, rv)
check_undo_redo(ns, marks[1], 0, 3, 0, 6)
end)
@@ -909,9 +916,9 @@ describe('API/extmarks', function()
-- Set the mark before the cursor, should stay there
set_extmark(ns, marks[2], 0, 10)
feed("i<cr><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
- rv = curbufmeths.get_extmark_by_id(ns, marks[2], false)
+ rv = get_extmark_by_id(ns, marks[2])
eq({0, 10}, rv)
check_undo_redo(ns, marks[1], 0, 12, 1, 3)
end)
@@ -924,12 +931,12 @@ describe('API/extmarks', function()
feed("0iint <esc>A {<cr><esc>0i1M1<esc>")
set_extmark(ns, marks[1], 1, 1)
feed("0i<c-f><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
check_undo_redo(ns, marks[1], 1, 1, 1, 3)
-- now check when cursor at eol
feed("uA<c-f><esc>")
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({1, 3}, rv)
end)
@@ -940,12 +947,12 @@ describe('API/extmarks', function()
feed("0i<tab><esc>")
set_extmark(ns, marks[1], 0, 3)
feed("bi<c-d><esc>")
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, 1}, rv)
check_undo_redo(ns, marks[1], 0, 3, 0, 1)
-- check when cursor at eol
feed("uA<c-d><esc>")
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({0, 1}, rv)
end)
@@ -1075,7 +1082,7 @@ describe('API/extmarks', function()
check_undo_redo(ns, marks[5], 2, 0, 3, 0)
feed('u')
feed([[:1,2s:3:\rxx<cr>]])
- eq({1, 3}, curbufmeths.get_extmark_by_id(ns, marks[3], false))
+ eq({1, 3}, get_extmark_by_id(ns, marks[3]))
end)
it('substitions over multiple lines with replace in substition', function()
@@ -1314,16 +1321,16 @@ describe('API/extmarks', function()
eq("Invalid ns_id", pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]))
eq("Invalid ns_id", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1]))
eq("Invalid ns_id", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
- eq("Invalid ns_id", pcall_err(curbufmeths.get_extmark_by_id, ns_invalid, marks[1], false))
+ eq("Invalid ns_id", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end)
it('when col = line-length, set the mark on eol', function()
set_extmark(ns, marks[1], 0, -1)
- local rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ local rv = get_extmark_by_id(ns, marks[1])
eq({0, init_text:len()}, rv)
-- Test another
set_extmark(ns, marks[1], 0, -1)
- rv = curbufmeths.get_extmark_by_id(ns, marks[1], false)
+ rv = get_extmark_by_id(ns, marks[1])
eq({0, init_text:len()}, rv)
end)
@@ -1336,7 +1343,7 @@ describe('API/extmarks', function()
local invalid_col = init_text:len() + 1
local invalid_lnum = 3
eq('line value outside range', pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col))
- eq({}, curbufmeths.get_extmark_by_id(ns, marks[1], false))
+ eq({}, get_extmark_by_id(ns, marks[1]))
end)
it('bug from check_col in extmark_set', function()
@@ -1361,7 +1368,7 @@ describe('API/extmarks', function()
local buf = request('nvim_create_buf', 0, 1)
request('nvim_buf_set_lines', buf, 0, -1, 1, {"", ""})
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
- eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}, false))
+ eq({{id, 1, 0}}, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
end)
it('does not crash with append/delete/undo seqence', function()
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index e8435cd3b7..e4fb95442c 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -769,14 +769,14 @@ end
function module.missing_provider(provider)
if provider == 'ruby' or provider == 'node' or provider == 'perl' then
- local prog = module.funcs['provider#' .. provider .. '#Detect']()
- return prog == '' and (provider .. ' not detected') or false
+ local e = module.funcs['provider#'..provider..'#Detect']()[2]
+ return e ~= '' and e or false
elseif provider == 'python' or provider == 'python3' then
local py_major_version = (provider == 'python3' and 3 or 2)
- local errors = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
- return errors ~= '' and errors or false
+ local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
+ return e ~= '' and e or false
else
- assert(false, 'Unknown provider: ' .. provider)
+ assert(false, 'Unknown provider: '..provider)
end
end
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index aa36e6f8f0..5bca42a4fc 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -250,13 +250,13 @@ void ui_refresh(void)
}, res)
end)
- it('allow loading query with escaped quotes and capture them with `match?` and `vim-match?`', function()
+ it('allow loading query with escaped quotes and capture them with `lua-match?` and `vim-match?`', function()
if not check_parser() then return end
insert('char* astring = "Hello World!";')
local res = exec_lua([[
- cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (match? @quote "^\\"$"))')
+ cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (lua-match? @quote "^\\"$"))')
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()
res = {}
@@ -312,6 +312,18 @@ void ui_refresh(void)
]], custom_query)
eq({{0, 4, 0, 8}}, res)
+
+ local res_list = exec_lua[[
+ local query = require'vim.treesitter.query'
+
+ local list = query.list_predicates()
+
+ table.sort(list)
+
+ return list
+ ]]
+
+ eq({ 'contains?', 'eq?', 'is-main?', 'lua-match?', 'match?', 'vim-match?' }, res_list)
end)
it('supports highlighting', function()
@@ -361,7 +373,7 @@ static int nlua_schedule(lua_State *const lstate)
; Use lua regexes
((identifier) @Identifier (#contains? @Identifier "lua_"))
-((identifier) @Constant (#match? @Constant "^[A-Z_]+$"))
+((identifier) @Constant (#lua-match? @Constant "^[A-Z_]+$"))
((identifier) @Normal (#vim-match? @Constant "^lstate$"))
((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) (#eq? @WarningMsg.left @WarningMsg.right))
diff --git a/test/functional/provider/perl_spec.lua b/test/functional/provider/perl_spec.lua
index 7b446e4ab3..125674660b 100644
--- a/test/functional/provider/perl_spec.lua
+++ b/test/functional/provider/perl_spec.lua
@@ -5,6 +5,10 @@ local command = helpers.command
local write_file = helpers.write_file
local eval = helpers.eval
local retry = helpers.retry
+local curbufmeths = helpers.curbufmeths
+local insert = helpers.insert
+local expect = helpers.expect
+local feed = helpers.feed
do
clear()
@@ -19,7 +23,51 @@ before_each(function()
clear()
end)
-describe('perl host', function()
+describe('legacy perl provider', function()
+ if helpers.pending_win32(pending) then return end
+
+ it('feature test', function()
+ eq(1, eval('has("perl")'))
+ end)
+
+ it(':perl command', function()
+ command('perl $vim->vars->{set_by_perl} = [100, 0];')
+ eq({100, 0}, eval('g:set_by_perl'))
+ end)
+
+ it(':perlfile command', function()
+ local fname = 'perlfile.pl'
+ write_file(fname, '$vim->command("let set_by_perlfile = 123")')
+ command('perlfile perlfile.pl')
+ eq(123, eval('g:set_by_perlfile'))
+ os.remove(fname)
+ end)
+
+ it(':perldo command', function()
+ -- :perldo 1; doesn't change $_,
+ -- the buffer should not be changed
+ command('normal :perldo 1;')
+ eq(false, curbufmeths.get_option('modified'))
+ -- insert some text
+ insert('abc\ndef\nghi')
+ expect([[
+ abc
+ def
+ ghi]])
+ -- go to top and select and replace the first two lines
+ feed('ggvj:perldo $_ = reverse ($_)."$linenr"<CR>')
+ expect([[
+ cba1
+ fed2
+ ghi]])
+ end)
+
+ it('perleval()', function()
+ eq({1, 2, {['key'] = 'val'}}, eval([[perleval('[1, 2, {"key" => "val"}]')]]))
+ end)
+end)
+
+describe('perl provider', function()
if helpers.pending_win32(pending) then return end
teardown(function ()
os.remove('Xtest-perl-hello.pl')
diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua
index 0262a5b59b..d7269d2c29 100644
--- a/test/functional/ui/bufhl_spec.lua
+++ b/test/functional/ui/bufhl_spec.lua
@@ -699,14 +699,14 @@ describe('Buffer highlighting', function()
-- TODO: only a virtual text from the same ns curretly overrides
-- an existing virtual text. We might add a prioritation system.
set_virtual_text(id1, 0, s1, {})
- eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {}, true))
+ eq({{1, 0, 0, {virt_text = s1}}}, get_extmarks(id1, {0,0}, {0, -1}, {details=true}))
-- TODO: is this really valid? shouldn't the max be line_count()-1?
local lastline = line_count()
set_virtual_text(id1, line_count(), s2, {})
- eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {}, true))
+ eq({{3, lastline, 0, {virt_text = s2}}}, get_extmarks(id1, {lastline,0}, {lastline, -1}, {details=true}))
- eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}, false))
+ eq({}, get_extmarks(id1, {lastline+9000,0}, {lastline+9000, -1}, {}))
end)
it('is not highlighted by visual selection', function()