diff options
Diffstat (limited to 'test/functional')
| -rw-r--r-- | test/functional/api/server_notifications_spec.lua | 16 | ||||
| -rw-r--r-- | test/functional/eval/api_functions_spec.lua | 4 | ||||
| -rw-r--r-- | test/functional/eval/null_spec.lua | 2 | ||||
| -rw-r--r-- | test/functional/eval/timer_spec.lua | 4 | ||||
| -rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 23 | ||||
| -rw-r--r-- | test/functional/lua/treesitter_spec.lua | 102 | ||||
| -rw-r--r-- | test/functional/provider/clipboard_spec.lua | 8 | ||||
| -rw-r--r-- | test/functional/ui/float_spec.lua | 43 | ||||
| -rw-r--r-- | test/functional/ui/fold_spec.lua | 70 | ||||
| -rw-r--r-- | test/functional/ui/screen.lua | 4 | ||||
| -rw-r--r-- | test/functional/ui/searchhl_spec.lua | 27 | ||||
| -rw-r--r-- | test/functional/ui/sign_spec.lua | 66 |
12 files changed, 338 insertions, 31 deletions
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua index 29cd38ef0d..9ee2570798 100644 --- a/test/functional/api/server_notifications_spec.lua +++ b/test/functional/api/server_notifications_spec.lua @@ -3,6 +3,8 @@ local eq, clear, eval, command, nvim, next_msg = helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_msg local meths = helpers.meths +local exec_lua = helpers.exec_lua +local retry = helpers.retry describe('notify', function() local channel @@ -72,4 +74,18 @@ describe('notify', function() nvim('unsubscribe', 'event1') eq(2, eval('1+1')) -- Still alive? end) + + it('cancels stale events on channel close', function() + if helpers.pending_win32(pending) then return end + local catchan = eval("jobstart(['cat'], {'rpc': v:true})") + eq({id=catchan, stream='job', mode='rpc', client = {}}, exec_lua ([[ + vim.rpcnotify(..., "nvim_call_function", 'chanclose', {..., 'rpc'}) + vim.rpcnotify(..., "nvim_subscribe", "daily_rant") + return vim.api.nvim_get_chan_info(...) + ]], catchan)) + eq(2, eval('1+1')) -- Still alive? + eq({false, 'Invalid channel: '..catchan}, + exec_lua ([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan)) + retry(nil, 3000, function() eq({}, meths.get_chan_info(catchan)) end) -- cat be dead :( + end) end) diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/eval/api_functions_spec.lua index ed110efeb4..7d09a652ba 100644 --- a/test/functional/eval/api_functions_spec.lua +++ b/test/functional/eval/api_functions_spec.lua @@ -47,6 +47,10 @@ describe('eval-API', function() eq('Vim(call):E5555: API call: Invalid buffer id: 17', err) end) + it('cannot change texts if textlocked', function() + command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])") + eq('Vim(call):E5555: API call: E523: Not allowed here', pcall_err(command, "normal! yy")) + end) it("use buffer numbers and windows ids as handles", function() local screen = Screen.new(40, 8) diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index fa8f7d873f..bef41e52d4 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -121,7 +121,7 @@ describe('NULL', function() null_test('does not make Neovim crash when v:oldfiles gets assigned to that', ':let v:oldfiles = L|oldfiles', 0) null_expr_test('does not make complete() crash or error out', 'execute(":normal i\\<C-r>=complete(1, L)[-1]\\n")', - '', '\n', function() + 0, '', function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index 9ee0735e40..3f57568b8e 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -130,12 +130,12 @@ describe('timers', function() nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})") screen:expect([[ - ITEM 1 | + ^ITEM 1 | ITEM 2 | {1:~ }| {1:~ }| {1:~ }| - ^ | + | ]]) nvim_async("command", "let g:cont = 1") diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 7e4de7c39a..9f2b1b6e52 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -25,14 +25,14 @@ local function attach_buffer(evname) local evname = ... local events = {} - function test_register(bufnr, id, changedtick, utf_sizes) + function test_register(bufnr, id, changedtick, utf_sizes, preview) local function callback(...) table.insert(events, {id, ...}) if test_unreg == id then return true end end - local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes} + local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes, preview=preview} if changedtick then opts.on_changedtick = callback end @@ -290,7 +290,7 @@ describe('lua: nvim_buf_attach on_bytes', function() if verify then meths.buf_get_offset(0, meths.buf_line_count(0)) end - exec_lua("return test_register(...)", 0, "test1",false, nil) + exec_lua("return test_register(...)", 0, "test1", false, false, true) meths.buf_get_changedtick(0) local verify_name = "test1" @@ -493,6 +493,23 @@ describe('lua: nvim_buf_attach on_bytes', function() } end) + + it('inccomand=nosplit and substitute', function() + if verify then pending("Verification can't be done when previewing") end + + local check_events = setup_eventcheck(verify, {"abcde"}) + meths.set_option('inccommand', 'nosplit') + + feed ':%s/bcd/' + check_events { + { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 }; + } + + feed 'a' + check_events { + { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 }; + } + end) end describe('(with verify) handles', function() diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index f34cbbb65b..e522c339a9 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -871,12 +871,12 @@ local hl_query = [[ before_each(function() insert([[ - int x = INT_MAX; - #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - #define READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) - #define VALUE 0 - #define VALUE1 1 - #define VALUE2 2 +int x = INT_MAX; +#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) +#define READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) +#define VALUE 123 +#define VALUE1 123 +#define VALUE2 123 ]]) end) @@ -891,12 +891,12 @@ local hl_query = [[ eq("table", exec_lua("return type(parser:children().c)")) eq(5, exec_lua("return #parser:children().c:trees()")) eq({ - {0, 2, 7, 0}, -- root tree - {3, 16, 3, 17}, -- VALUE 0 - {4, 17, 4, 18}, -- VALUE1 1 - {5, 17, 5, 18}, -- VALUE2 2 - {1, 28, 1, 67}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) - {2, 31, 2, 70} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) + {0, 0, 7, 0}, -- root tree + {3, 14, 3, 17}, -- VALUE 123 + {4, 15, 4, 18}, -- VALUE1 123 + {5, 15, 5, 18}, -- VALUE2 123 + {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) + {2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) }, get_ranges()) end) end) @@ -912,15 +912,35 @@ local hl_query = [[ eq("table", exec_lua("return type(parser:children().c)")) eq(2, exec_lua("return #parser:children().c:trees()")) eq({ - {0, 2, 7, 0}, -- root tree - {3, 16, 5, 18}, -- VALUE 0 - -- VALUE1 1 - -- VALUE2 2 - {1, 28, 2, 70} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) + {0, 0, 7, 0}, -- root tree + {3, 14, 5, 18}, -- VALUE 123 + -- VALUE1 123 + -- VALUE2 123 + {1, 26, 2, 68} -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) }, get_ranges()) end) end) + + describe("when using the offset directive", function() + it("should shift the range by the directive amount", function() + exec_lua([[ + parser = vim.treesitter.get_parser(0, "c", { + queries = { + c = "(preproc_def ((preproc_arg) @c (#offset! @c 0 2 0 -1))) (preproc_function_def value: (preproc_arg) @c)"}}) + ]]) + + eq("table", exec_lua("return type(parser:children().c)")) + eq({ + {0, 0, 7, 0}, -- root tree + {3, 15, 3, 16}, -- VALUE 123 + {4, 16, 4, 17}, -- VALUE1 123 + {5, 16, 5, 17}, -- VALUE2 123 + {1, 26, 1, 65}, -- READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) + {2, 29, 2, 68} -- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y)) + }, get_ranges()) + end) + end) end) describe("when getting the language for a range", function() @@ -944,4 +964,52 @@ int x = INT_MAX; eq(result, true) end) end) + + describe("when getting/setting match data", function() + describe("when setting for the whole match", function() + it("should set/get the data correctly", function() + insert([[ + int x = 3; + ]]) + + local result = exec_lua([[ + local result + + query = vim.treesitter.parse_query("c", '((number_literal) @number (#set! "key" "value"))') + parser = vim.treesitter.get_parser(0, "c") + + for pattern, match, metadata in query:iter_matches(parser:parse()[1]:root(), 0, 0, 1) do + result = metadata.key + end + + return result + ]]) + + eq(result, "value") + end) + end) + + describe("when setting for a capture match", function() + it("should set/get the data correctly", function() + insert([[ + int x = 3; + ]]) + + local result = exec_lua([[ + local result + + query = vim.treesitter.parse_query("c", '((number_literal) @number (#set! @number "key" "value"))') + parser = vim.treesitter.get_parser(0, "c") + + for pattern, match, metadata in query:iter_matches(parser:parse()[1]:root(), 0, 0, 1) do + result = metadata[pattern].key + end + + return result + ]]) + + eq(result, "value") + end) + end) + end) end) diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index 1431054494..2c681eb9d8 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -605,10 +605,10 @@ describe('clipboard (with fake clipboard.vim)', function() {0:~ }| {4: }| :registers | - {1:--- Registers ---} | - "* some{2:^J}star data{2:^J} | - "+ such{2:^J}plus{2:^J}stuff | - ": let g:test_clip['+'] = ['such', 'plus', 'stuff'] | + {1:Type Name Content} | + l "* some{2:^J}star data{2:^J} | + c "+ such{2:^J}plus{2:^J}stuff | + c ": let g:test_clip['+'] = ['such', 'plus', 'stuff'] | {3:Press ENTER or type command to continue}^ | ]], { [0] = {bold = true, foreground = Screen.colors.Blue}, diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 32f9ae030f..8d654f6e5b 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -5344,6 +5344,45 @@ describe('floatwin', function() -- at least. Also check invisible EndOfBuffer region blends correctly. meths.buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"}) win = meths.open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [3:----------------------------------------]| + ## grid 2 + # TODO: 测试字典信息的准确性 | + # FIXME: 测试字典信息的准确^性 | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + | + ## grid 6 + {1: x x x xx}| + {1: x x x x}| + {1: }| + ]], float_pos={ + [6] = { { + id = 1003 + }, "NW", 1, 0, 11, true } + }} + else + screen:expect{grid=[[ + # TODO: 测 {1: x x x xx} 确性 | + # FIXME: 测{1: x x x x}准确^性 | + {0:~ }{1: }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + end meths.win_set_option(win, 'winblend', 30) screen:set_default_attr_ids({ [1] = {foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff')}, @@ -5381,7 +5420,7 @@ describe('floatwin', function() }, "NW", 1, 0, 11, true } }} else - screen:expect([[ + screen:expect{grid=[[ # TODO: 测 {2: x x x}{1:息}{2: xx} 确性 | # FIXME: 测{1:试}{2:x x x}{1:息}{2: x}准确^性 | {3:~ }{4: }{3: }| @@ -5389,7 +5428,7 @@ describe('floatwin', function() {3:~ }| {3:~ }| | - ]]) + ]]} end meths.win_set_config(win, {relative='editor', row=0, col=12}) diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 7b05e90459..6ce8b33a63 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -886,6 +886,41 @@ describe("folded lines", function() | ]]) end + command("set foldcolumn=auto") + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:+}{5:^+-- 2 lines: line 1························}| + {7: }line 3 | + {7: }line 4 | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ]], unchanged=true} + else + screen:expect{grid=[[ + {7:+}{5:^+-- 2 lines: line 1························}| + {7: }line 3 | + {7: }line 4 | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged=true} + end -- fdc should not change with a new fold as the maximum is 1 feed("zf3j") @@ -924,6 +959,41 @@ describe("folded lines", function() ]]) end + command("set foldcolumn=auto:1") + if multigrid then screen:expect{grid=[[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:+}{5:^+-- 4 lines: line 1························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + | + ]], unchanged=true} + else + screen:expect{grid=[[ + {7:+}{5:^+-- 4 lines: line 1························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]], unchanged=true} + end + -- relax the maximum fdc thus fdc should expand to -- accomodate the current number of folds command("set foldcolumn=auto:4") diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 8fa9fcc42f..5104c58796 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -807,7 +807,9 @@ function Screen:_handle_mouse_off() end function Screen:_handle_mode_change(mode, idx) - assert(mode == self._mode_info[idx+1].name) + if self._mode_info ~= nil then + assert(mode == self._mode_info[idx+1].name) + end self.mode = mode end diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index 222275eb4d..3bb72303bf 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -20,6 +20,8 @@ describe('search highlighting', function() [2] = {background = colors.Yellow}, -- Search [3] = {reverse = true}, [4] = {foreground = colors.Red}, -- Message + [5] = {bold = true, reverse = true}, + [6] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey}, -- Folded }) end) @@ -38,6 +40,21 @@ describe('search highlighting', function() ]]) end) + it('is disabled in folded text', function() + insert("some text\nmore text") + feed_command('1,2fold') + feed("gg/text") + screen:expect([[ + {6:+-- 2 lines: some text·················}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + /text^ | + ]]) + end) + it('works', function() insert([[ some text @@ -159,7 +176,15 @@ describe('search highlighting', function() ]]) feed('/foo') helpers.poke_eventloop() - screen:expect_unchanged() + screen:expect{grid=[[ + {3:foo} bar baz {3:│} | + bar baz {2:foo} {3:│} | + bar {2:foo} baz {3:│} | + {3:│} | + {1:~ }{3:│} | + {5:[No Name] [+] }{3:term }| + /foo^ | + ]]} end) it('works with incsearch', function() diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index 0ed62b21b2..d1b8de5e4e 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -76,6 +76,28 @@ describe('Signs', function() ]]) end) + it('allows signs with no text', function() + feed('ia<cr>b<cr><esc>') + command('sign define piet1 text= texthl=Search') + command('sign place 1 line=1 name=piet1 buffer=1') + screen:expect([[ + a | + b | + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) + it('can be called right after :split', function() feed('ia<cr>b<cr>c<cr><esc>gg') -- This used to cause a crash due to :sign using a special redraw @@ -244,6 +266,50 @@ describe('Signs', function() ]]} end) + it('ignores signs with no icon and text when calculting the signcolumn width', function() + feed('ia<cr>b<cr>c<cr><esc>') + command('set number') + command('set signcolumn=auto:2') + command('sign define pietSearch text=>> texthl=Search') + command('sign define pietError text= texthl=Error') + command('sign place 2 line=1 name=pietError buffer=1') + -- no signcolumn with only empty sign + screen:expect([[ + {6: 1 }a | + {6: 2 }b | + {6: 3 }c | + {6: 4 }^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + -- single column with 1 sign with text and one sign without + command('sign place 1 line=1 name=pietSearch buffer=1') + screen:expect([[ + {1:>>}{6: 1 }a | + {2: }{6: 2 }b | + {2: }{6: 3 }c | + {2: }{6: ^4 } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end) + it('can have 32bit sign IDs', function() command('sign define piet text=>> texthl=Search') command('sign place 100000 line=1 name=piet buffer=1') |