diff options
Diffstat (limited to 'test/functional/api')
-rw-r--r-- | test/functional/api/extmark_spec.lua | 206 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 122 |
2 files changed, 317 insertions, 11 deletions
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index e298eb3582..bc8d811c6d 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1606,3 +1606,209 @@ describe('Extmarks buffer api with many marks', function() eq({}, get_marks(ns2)) end) end) + +describe('API/win_extmark', function() + local screen + local marks, line1, line2 + local ns + + before_each(function() + -- Initialize some namespaces and insert text into a buffer + marks = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} + + line1 = "non ui-watched line" + line2 = "ui-watched line" + + clear() + + insert(line1) + feed("o<esc>") + insert(line2) + ns = request('nvim_create_namespace', "extmark-ui") + end) + + it('sends and only sends ui-watched marks to ui', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched lin^e | + ~ | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + } + }, + }) + end) + + it('sends multiple ui-watched marks to ui', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send all of these + set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = "overlay" }) + set_extmark(ns, marks[5], 1, 8, { ui_watched = true }) + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched lin^e | + ~ | + | + ]], + extmarks = { + [2] = { + -- earlier notifications + { {id = 1000}, 1, 1, 1, 0 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, { {id = 1000}, 1, 3, 1, 4 }, + { {id = 1000}, 1, 1, 1, 0 }, { {id = 1000}, 1, 2, 1, 2 }, { {id = 1000}, 1, 3, 1, 4 }, { {id = 1000}, 1, 4, 1, 6 }, + -- final + -- overlay + { {id = 1000}, 1, 1, 1, 0 }, + { {id = 1000}, 1, 2, 1, 2 }, + { {id = 1000}, 1, 3, 1, 4 }, + { {id = 1000}, 1, 4, 1, 6 }, + -- eol + { {id = 1000}, 1, 5, 1, 16 }, + } + }, + }) + end) + + it('updates ui-watched marks', function() + screen = Screen.new(20, 4) + screen:attach() + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + -- make some changes + insert(" update") + screen:expect({ + grid = [[ + non ui-watched line | + ui-watched linupdat^e| + e | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated and wrapped to 3rd line + { {id = 1000}, 1, 1, 2, 2 }, + } + } + }) + feed("<c-e>") + screen:expect({ + grid = [[ + ui-watched linupdat^e| + e | + ~ | + | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated and wrapped to 3rd line + { {id = 1000}, 1, 1, 2, 2 }, + -- scrolled up one line, should be handled by grid scroll + } + } + }) + end) + + it('sends ui-watched to splits', function() + screen = Screen.new(20, 8) + screen:attach({ext_multigrid=true}) + -- should send this + set_extmark(ns, marks[1], 1, 0, { ui_watched = true }) + -- should not send this + set_extmark(ns, marks[2], 0, 0, { ui_watched = false }) + command('split') + screen:expect({ + grid = [[ + ## grid 1 + [4:--------------------]| + [4:--------------------]| + [4:--------------------]| + [No Name] [+] | + [2:--------------------]| + [2:--------------------]| + [No Name] [+] | + [3:--------------------]| + ## grid 2 + non ui-watched line | + ui-watched line | + ## grid 3 + | + ## grid 4 + non ui-watched line | + ui-watched lin^e | + ~ | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated after split + { {id = 1000}, 1, 1, 1, 16 }, + }, + [4] = { + -- only after split + { {id = 1001}, 1, 1, 1, 16 }, + } + } + }) + -- make some changes + insert(" update") + screen:expect({ + grid = [[ + ## grid 1 + [4:--------------------]| + [4:--------------------]| + [4:--------------------]| + [No Name] [+] | + [2:--------------------]| + [2:--------------------]| + [No Name] [+] | + [3:--------------------]| + ## grid 2 + non ui-watched line | + ui-watched linupd@@@| + ## grid 3 + | + ## grid 4 + non ui-watched line | + ui-watched linupdat^e| + e | + ]], + extmarks = { + [2] = { + -- positioned at the end of the 2nd line + { {id = 1000}, 1, 1, 1, 16 }, + -- updated after split + { {id = 1000}, 1, 1, 1, 16 }, + }, + [4] = { + { {id = 1001}, 1, 1, 1, 16 }, + -- updated + { {id = 1001}, 1, 1, 2, 2 }, + } + } + }) + end) +end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e138e2cc38..7e54ae0248 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3104,8 +3104,11 @@ describe('API', function() cmd = 'echo', args = { 'foo' }, bang = false, - line1 = 1, - line2 = 1, + line1 = -1, + line2 = -1, + range = 0, + count = -1, + reg = '', addr = 'none', magic = { file = false, @@ -3130,7 +3133,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('echo foo', {})) end) @@ -3141,6 +3144,9 @@ describe('API', function() bang = false, line1 = 4, line2 = 6, + range = 2, + count = -1, + reg = '', addr = 'line', magic = { file = false, @@ -3165,10 +3171,86 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('4,6s/math.random/math.max/', {})) end) + it('works with count', function() + eq({ + cmd = 'buffer', + args = {}, + bang = false, + line1 = 1, + line2 = 1, + range = 1, + count = 1, + reg = '', + addr = 'buf', + magic = { + file = false, + bar = true + }, + nargs = '*', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + } + }, meths.parse_cmd('buffer 1', {})) + end) + it('works with register', function() + eq({ + cmd = 'put', + args = {}, + bang = false, + line1 = 1, + line2 = 1, + range = 0, + count = -1, + reg = '+', + addr = 'line', + magic = { + file = false, + bar = true + }, + nargs = '0', + nextcmd = '', + mods = { + browse = false, + confirm = false, + emsg_silent = false, + hide = false, + keepalt = false, + keepjumps = false, + keepmarks = false, + keeppatterns = false, + lockmarks = false, + noautocmd = false, + noswapfile = false, + sandbox = false, + silent = false, + vertical = false, + split = "", + tab = 0, + verbose = -1 + } + }, meths.parse_cmd('put +', {})) + end) it('works with bang', function() eq({ cmd = 'write', @@ -3176,6 +3258,9 @@ describe('API', function() bang = true, line1 = 1, line2 = 1, + range = 0, + count = -1, + reg = '', addr = 'line', magic = { file = true, @@ -3200,7 +3285,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 }, }, meths.parse_cmd('w!', {})) end) @@ -3211,6 +3296,9 @@ describe('API', function() bang = false, line1 = 1, line2 = 1, + range = 0, + count = -1, + reg = '', addr = '?', magic = { file = true, @@ -3247,6 +3335,9 @@ describe('API', function() bang = true, line1 = 4, line2 = 6, + range = 2, + count = -1, + reg = '', addr = 'line', magic = { file = false, @@ -3271,7 +3362,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('4,6MyCommand! test it', {})) end) @@ -3282,6 +3373,9 @@ describe('API', function() bang = false, line1 = 0, line2 = 0, + range = 0, + count = -1, + reg = '', addr = 'arg', magic = { file = true, @@ -3306,7 +3400,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('argadd a.txt | argadd b.txt', {})) end) @@ -3316,8 +3410,11 @@ describe('API', function() cmd = 'MyCommand', args = { 'test it' }, bang = false, - line1 = 1, - line2 = 1, + line1 = -1, + line2 = -1, + range = 0, + count = -1, + reg = '', addr = 'none', magic = { file = false, @@ -3342,7 +3439,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('MyCommand test it', {})) end) @@ -3355,6 +3452,9 @@ describe('API', function() bang = false, line1 = 1, line2 = 2, + range = 0, + count = -1, + reg = '', addr = 'buf', magic = { file = false, @@ -3379,7 +3479,7 @@ describe('API', function() vertical = false, split = "", tab = 0, - verbose = 0 + verbose = -1 } }, meths.parse_cmd('MyCommand', {})) end) |