diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/clipboard/clipboard_provider_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/core/job_spec.lua (renamed from test/functional/job/job_spec.lua) | 49 | ||||
-rw-r--r-- | test/functional/eval/execute_spec.lua (renamed from test/functional/eval/capture_spec.lua) | 32 | ||||
-rw-r--r-- | test/functional/fixtures/autoload/provider/clipboard.vim | 5 | ||||
-rw-r--r-- | test/functional/legacy/030_fileformats_spec.lua | 375 | ||||
-rw-r--r-- | test/functional/legacy/036_regexp_character_classes_spec.lua | 11 | ||||
-rw-r--r-- | test/functional/legacy/055_list_and_dict_types_spec.lua | 23 | ||||
-rw-r--r-- | test/functional/legacy/101_hlsearch_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/legacy/assert_spec.lua | 47 | ||||
-rw-r--r-- | test/functional/legacy/writefile_spec.lua | 1 | ||||
-rw-r--r-- | test/functional/provider/ruby_spec.lua | 96 | ||||
-rw-r--r-- | test/functional/ui/mouse_spec.lua | 317 | ||||
-rw-r--r-- | test/functional/ui/output_spec.lua | 39 |
13 files changed, 950 insertions, 49 deletions
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua index b4febe4bfb..15977b9777 100644 --- a/test/functional/clipboard/clipboard_provider_spec.lua +++ b/test/functional/clipboard/clipboard_provider_spec.lua @@ -308,6 +308,7 @@ describe('clipboard usage', function() end) it('links the "+ and unnamed registers', function() + eq('+', eval('v:register')) insert("one two") feed('^"+dwdw"+P') expect('two') @@ -335,6 +336,7 @@ describe('clipboard usage', function() eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['*']")) -- unnamedplus takes predecence when pasting + eq('+', eval('v:register')) execute("let g:test_clip['+'] = ['the plus','']") execute("let g:test_clip['*'] = ['the star','']") feed("p") diff --git a/test/functional/job/job_spec.lua b/test/functional/core/job_spec.lua index b54d5166ac..61ecdd1835 100644 --- a/test/functional/job/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -1,4 +1,3 @@ - local helpers = require('test.functional.helpers')(after_each) local clear, eq, eval, execute, feed, insert, neq, next_msg, nvim, nvim_dir, ok, source, write_file, mkdir, rmdir = helpers.clear, @@ -120,7 +119,7 @@ describe('jobs', function() {0, {'a', '', 'c', '', '', '', 'b', '', ''}}}, next_msg()) end) - it('can preserve nuls', function() + it('can preserve NULs', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') eq({'notification', 'stdout', {0, {'\n123\n', 'abc\nxyz\n', ''}}}, @@ -144,7 +143,7 @@ describe('jobs', function() eq({'notification', 'exit', {0, 0}}, next_msg()) end) - it("won't allow jobsend with a job that closed stdin", function() + it("disallows jobsend on a job that closed stdin", function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobclose(j, "stdin")') eq(false, pcall(function() @@ -152,12 +151,12 @@ describe('jobs', function() end)) end) - it('will not allow jobsend/stop on a non-existent job', function() + it('disallows jobsend/stop on a non-existent job', function() eq(false, pcall(eval, "jobsend(-1, 'lol')")) eq(false, pcall(eval, "jobstop(-1)")) end) - it('will not allow jobstop twice on the same job', function() + it('disallows jobstop twice on the same job', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") neq(0, eval('j')) eq(true, pcall(eval, "jobstop(j)")) @@ -244,7 +243,7 @@ describe('jobs', function() eq({'notification', 'exit', {45, 10}}, next_msg()) end) - it('cant redefine callbacks being used by a job', function() + it('cannot redefine callbacks being used by a job', function() local screen = Screen.new() screen:attach() local script = [[ @@ -467,3 +466,41 @@ describe('jobs', function() end) end) end) + +describe("pty process teardown", function() + local screen + before_each(function() + clear() + screen = Screen.new(30, 6) + screen:attach() + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + | + ]]) + end) + after_each(function() + screen:detach() + end) + + it("does not prevent/delay exit. #4798 #4900", function() + -- Use a nested nvim (in :term) to test without --headless. + execute(":terminal '"..helpers.nvim_prog + -- Use :term again in the _nested_ nvim to get a PTY process. + -- Use `sleep` to simulate a long-running child of the PTY. + .."' +terminal +'!(sleep 300 &)' +qa") + + -- Exiting should terminate all descendants (PTY, its children, ...). + screen:expect([[ + | + [Process exited 0] | + | + | + | + -- TERMINAL -- | + ]]) + end) +end) diff --git a/test/functional/eval/capture_spec.lua b/test/functional/eval/execute_spec.lua index d9265f1b5b..a91a04341f 100644 --- a/test/functional/eval/capture_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -9,16 +9,16 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local feed = helpers.feed -describe('capture()', function() +describe('execute()', function() before_each(clear) it('returns the same result with :redir', function() - eq(redir_exec('messages'), funcs.capture('messages')) + eq(redir_exec('messages'), funcs.execute('messages')) end) it('returns the output of the commands if the argument is List', function() - eq("foobar", funcs.capture({'echon "foo"', 'echon "bar"'})) - eq("\nfoo\nbar", funcs.capture({'echo "foo"', 'echo "bar"'})) + eq("foobar", funcs.execute({'echon "foo"', 'echon "bar"'})) + eq("\nfoo\nbar", funcs.execute({'echo "foo"', 'echo "bar"'})) end) it('supports the nested redirection', function() @@ -38,34 +38,34 @@ describe('capture()', function() return a endfunction ]]) - eq('foo', funcs.capture('call g:Bar()')) + eq('foo', funcs.execute('call g:Bar()')) - eq('42', funcs.capture([[echon capture("echon capture('echon 42')")]])) + eq('42', funcs.execute([[echon execute("echon execute('echon 42')")]])) end) it('returns the transformed string', function() - eq('^A', funcs.capture('echon "\\<C-a>"')) + eq('^A', funcs.execute('echon "\\<C-a>"')) end) it('returns the empty string if the argument list is empty', function() - eq('', funcs.capture({})) - eq(0, exc_exec('let g:ret = capture(v:_null_list)')) + eq('', funcs.execute({})) + eq(0, exc_exec('let g:ret = execute(v:_null_list)')) eq('', eval('g:ret')) end) it('returns the errors', function() local ret - ret = exc_exec('call capture(0.0)') + ret = exc_exec('call execute(0.0)') eq('Vim(call):E806: using Float as a String', ret) - ret = exc_exec('call capture(v:_null_dict)') + ret = exc_exec('call execute(v:_null_dict)') eq('Vim(call):E731: using Dictionary as a String', ret) - ret = exc_exec('call capture(function("tr"))') + ret = exc_exec('call execute(function("tr"))') eq('Vim(call):E729: using Funcref as a String', ret) - ret = exc_exec('call capture(["echo 42", 0.0, "echo 44"])') + ret = exc_exec('call execute(["echo 42", 0.0, "echo 44"])') eq('Vim(call):E806: using Float as a String', ret) - ret = exc_exec('call capture(["echo 42", v:_null_dict, "echo 44"])') + ret = exc_exec('call execute(["echo 42", v:_null_dict, "echo 44"])') eq('Vim(call):E731: using Dictionary as a String', ret) - ret = exc_exec('call capture(["echo 42", function("tr"), "echo 44"])') + ret = exc_exec('call execute(["echo 42", function("tr"), "echo 44"])') eq('Vim(call):E729: using Funcref as a String', ret) end) @@ -73,7 +73,7 @@ describe('capture()', function() local screen = Screen.new(20, 5) screen:attach() screen:set_default_attr_ignore({{bold=true, foreground=255}}) - feed(':let g:mes = capture("echon 42")<CR>') + feed(':let g:mes = execute("echon 42")<CR>') screen:expect([[ ^ | ~ | diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim index 0935ea45ff..411e095c71 100644 --- a/test/functional/fixtures/autoload/provider/clipboard.vim +++ b/test/functional/fixtures/autoload/provider/clipboard.vim @@ -9,13 +9,12 @@ function! s:methods.get(reg) if g:cliperror return 0 end - let reg = a:reg == '"' ? '+' : a:reg if g:cliplossy " behave like pure text clipboard - return g:test_clip[reg][0] + return g:test_clip[a:reg][0] else " behave like VIMENC clipboard - return g:test_clip[reg] + return g:test_clip[a:reg] end endfunction diff --git a/test/functional/legacy/030_fileformats_spec.lua b/test/functional/legacy/030_fileformats_spec.lua new file mode 100644 index 0000000000..9bc62a375e --- /dev/null +++ b/test/functional/legacy/030_fileformats_spec.lua @@ -0,0 +1,375 @@ +-- Test for a lot of variations of the 'fileformats' option + +local helpers = require('test.functional.helpers')(after_each) +local feed, clear, execute = helpers.feed, helpers.clear, helpers.execute +local eq, write_file = helpers.eq, helpers.write_file + +describe('fileformats option', function() + setup(function() + clear() + local dos = 'dos\r\ndos\r\n' + local mac = 'mac\rmac\r' + local unix = 'unix\nunix\n' + local eol = 'noeol' + write_file('XXDos', dos) + write_file('XXMac', mac) + write_file('XXUnix', unix) + write_file('XXEol', eol) + write_file('XXDosMac', dos..mac) + write_file('XXMacEol', mac..eol) + write_file('XXUxDs', unix..dos) + write_file('XXUxDsMc', unix..dos..mac) + write_file('XXUxMac', unix..mac) + end) + + teardown(function() + os.remove('test.out') + os.remove('XXDos') + os.remove('XXMac') + os.remove('XXUnix') + os.remove('XXEol') + os.remove('XXDosMac') + os.remove('XXMacEol') + os.remove('XXUxDs') + os.remove('XXUxDsMc') + os.remove('XXUxMac') + for i = 0, 9 do + for j = 1, 4 do + os.remove('XXtt'..i..j) + end + end + end) + + it('is working', function() + + -- Try reading and writing with 'fileformats' empty. + execute('set fileformats=') + execute('set fileformat=unix') + execute('e! XXUnix') + execute('w! test.out') + execute('e! XXDos') + execute('w! XXtt01') + execute('e! XXMac') + execute('w! XXtt02') + execute('bwipe XXUnix XXDos XXMac') + execute('set fileformat=dos') + execute('e! XXUnix') + execute('w! XXtt11') + execute('e! XXDos') + execute('w! XXtt12') + execute('e! XXMac') + execute('w! XXtt13') + execute('bwipe XXUnix XXDos XXMac') + execute('set fileformat=mac') + execute('e! XXUnix') + execute('w! XXtt21') + execute('e! XXDos') + execute('w! XXtt22') + execute('e! XXMac') + execute('w! XXtt23') + execute('bwipe XXUnix XXDos XXMac') + + -- Try reading and writing with 'fileformats' set to one format. + execute('set fileformats=unix') + execute('e! XXUxDsMc') + execute('w! XXtt31') + execute('bwipe XXUxDsMc') + execute('set fileformats=dos') + execute('e! XXUxDsMc') + execute('w! XXtt32') + execute('bwipe XXUxDsMc') + execute('set fileformats=mac') + execute('e! XXUxDsMc') + execute('w! XXtt33') + execute('bwipe XXUxDsMc') + + -- Try reading and writing with 'fileformats' set to two formats. + execute('set fileformats=unix,dos') + execute('e! XXUxDsMc') + execute('w! XXtt41') + execute('bwipe XXUxDsMc') + execute('e! XXUxMac') + execute('w! XXtt42') + execute('bwipe XXUxMac') + execute('e! XXDosMac') + execute('w! XXtt43') + execute('bwipe XXDosMac') + execute('set fileformats=unix,mac') + execute('e! XXUxDs') + execute('w! XXtt51') + execute('bwipe XXUxDs') + execute('e! XXUxDsMc') + execute('w! XXtt52') + execute('bwipe XXUxDsMc') + execute('e! XXDosMac') + execute('w! XXtt53') + execute('bwipe XXDosMac') + execute('e! XXEol') + feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') + execute('w! XXtt54') + execute('bwipe XXEol') + execute('set fileformats=dos,mac') + execute('e! XXUxDs') + execute('w! XXtt61') + execute('bwipe XXUxDs') + execute('e! XXUxMac') + feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') + execute('w! XXtt62') + execute('bwipe XXUxMac') + execute('e! XXUxDsMc') + execute('w! XXtt63') + execute('bwipe XXUxDsMc') + execute('e! XXMacEol') + feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') + execute('w! XXtt64') + execute('bwipe XXMacEol') + + -- Try reading and writing with 'fileformats' set to three formats. + execute('set fileformats=unix,dos,mac') + execute('e! XXUxDsMc') + execute('w! XXtt71') + execute('bwipe XXUxDsMc') + execute('e! XXEol') + feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') + execute('w! XXtt72') + execute('bwipe XXEol') + execute('set fileformats=mac,dos,unix') + execute('e! XXUxDsMc') + execute('w! XXtt81') + execute('bwipe XXUxDsMc') + execute('e! XXEol') + feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') + execute('w! XXtt82') + execute('bwipe XXEol') + -- Try with 'binary' set. + execute('set fileformats=mac,unix,dos') + execute('set binary') + execute('e! XXUxDsMc') + execute('w! XXtt91') + execute('bwipe XXUxDsMc') + execute('set fileformats=mac') + execute('e! XXUxDsMc') + execute('w! XXtt92') + execute('bwipe XXUxDsMc') + execute('set fileformats=dos') + execute('e! XXUxDsMc') + execute('w! XXtt93') + + -- Append "END" to each file so that we can see what the last written + -- char was. + execute('set fileformat=unix nobin') + feed('ggdGaEND<esc>') + execute('w >>XXtt01') + execute('w >>XXtt02') + execute('w >>XXtt11') + execute('w >>XXtt12') + execute('w >>XXtt13') + execute('w >>XXtt21') + execute('w >>XXtt22') + execute('w >>XXtt23') + execute('w >>XXtt31') + execute('w >>XXtt32') + execute('w >>XXtt33') + execute('w >>XXtt41') + execute('w >>XXtt42') + execute('w >>XXtt43') + execute('w >>XXtt51') + execute('w >>XXtt52') + execute('w >>XXtt53') + execute('w >>XXtt54') + execute('w >>XXtt61') + execute('w >>XXtt62') + execute('w >>XXtt63') + execute('w >>XXtt64') + execute('w >>XXtt71') + execute('w >>XXtt72') + execute('w >>XXtt81') + execute('w >>XXtt82') + execute('w >>XXtt91') + execute('w >>XXtt92') + execute('w >>XXtt93') + + -- Concatenate the results. + -- Make fileformat of test.out the native fileformat. + -- Add a newline at the end. + execute('set binary') + execute('e! test.out') + execute('$r XXtt01') + execute('$r XXtt02') + feed('Go1<esc>') + execute('$r XXtt11') + execute('$r XXtt12') + execute('$r XXtt13') + feed('Go2<esc>') + execute('$r XXtt21') + execute('$r XXtt22') + execute('$r XXtt23') + feed('Go3<esc>') + execute('$r XXtt31') + execute('$r XXtt32') + execute('$r XXtt33') + feed('Go4<esc>') + execute('$r XXtt41') + execute('$r XXtt42') + execute('$r XXtt43') + feed('Go5<esc>') + execute('$r XXtt51') + execute('$r XXtt52') + execute('$r XXtt53') + execute('$r XXtt54') + feed('Go6<esc>') + execute('$r XXtt61') + execute('$r XXtt62') + execute('$r XXtt63') + execute('$r XXtt64') + feed('Go7<esc>') + execute('$r XXtt71') + execute('$r XXtt72') + feed('Go8<esc>') + execute('$r XXtt81') + execute('$r XXtt82') + feed('Go9<esc>') + execute('$r XXtt91') + execute('$r XXtt92') + execute('$r XXtt93') + feed('Go10<esc>') + execute('$r XXUnix') + execute('set nobinary ff&') + + -- Assert buffer contents. This has to be done manually as + -- helpers.expect() calls helpers.dedent() which messes up the white space + -- and carrige returns. + eq( + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'END\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + '1\n'.. + 'unix\r\n'.. + 'unix\r\n'.. + 'END\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'END\n'.. + 'mac\rmac\r\r\n'.. + 'END\n'.. + '2\n'.. + 'unix\n'.. + 'unix\n'.. + '\rEND\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + '\rEND\n'.. + 'mac\rmac\rEND\n'.. + '3\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'unix\r\n'.. + 'unix\r\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\r\n'.. + 'END\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\rEND\n'.. + '4\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'unix\n'.. + 'unix\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\r\n'.. + 'END\n'.. + '5\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'END\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\rEND\n'.. + 'unix,mac:unix\n'.. + 'noeol\n'.. + 'END\n'.. + '6\n'.. + 'unix\r\n'.. + 'unix\r\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'END\n'.. + 'dos,mac:dos\r\n'.. + 'unix\r\n'.. + 'unix\r\n'.. + 'mac\rmac\r\r\n'.. + 'END\n'.. + 'unix\r\n'.. + 'unix\r\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\r\n'.. + 'END\n'.. + 'dos,mac:mac\rmac\rmac\rnoeol\rEND\n'.. + '7\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'unix,dos,mac:unix\n'.. + 'noeol\n'.. + 'END\n'.. + '8\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\r\n'.. + 'END\n'.. + 'mac,dos,unix:mac\rnoeol\rEND\n'.. + '9\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\rEND\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\rEND\n'.. + 'unix\n'.. + 'unix\n'.. + 'dos\r\n'.. + 'dos\r\n'.. + 'mac\rmac\rEND\n'.. + '10\n'.. + 'unix\n'.. + 'unix', + helpers.curbuf_contents()) + end) +end) diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua index 3d5e69d1e5..9e67bb9429 100644 --- a/test/functional/legacy/036_regexp_character_classes_spec.lua +++ b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -268,4 +268,15 @@ describe('character classes in regexp', function() ABCDEFGHIXYZ ABCDEFGHIXYZ]]) end) + it([["\%1l^#.*" does not match on a line starting with "#". (vim-patch:7.4.1305)]], function() + source([[ + 1 s/\%#=0\%1l^\t...//g + 2 s/\%#=1\%2l^\t...//g + 3 s/\%#=2\%3l^\t...//g + 4 s/\%#=0\%4l^\t...//g + 5 s/\%#=1\%5l^\t...//g + 6 s/\%#=2\%6l^\t...//g]]) + diff(sixlines(string.sub(punct1, 1)..digits..punct2..upper..punct3.. + lower..punct4..ctrl2..iso_text)) + end) end) diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua index dee138e6d8..b9e5a8bc03 100644 --- a/test/functional/legacy/055_list_and_dict_types_spec.lua +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -112,29 +112,6 @@ describe('list and dictionary types', function() expect('\n101101') end) - it('changing var type should fail', function() - source([[ - lang C - " The list from the first test repeated after splitting the tests. - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - " The dict from the first test repeated after splitting the tests. - let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} - try - let d = [] - catch - $put =v:exception[:14] . v:exception[-1:-1] - endtry - try - let l = {} - catch - $put =v:exception[:14] . v:exception[-1:-1] - endtry]]) - expect([[ - - Vim(let):E706: d - Vim(let):E706: l]]) - end) - it('removing items with :unlet', function() source([[ lang C diff --git a/test/functional/legacy/101_hlsearch_spec.lua b/test/functional/legacy/101_hlsearch_spec.lua index 0d88e99278..fa29e5fbe8 100644 --- a/test/functional/legacy/101_hlsearch_spec.lua +++ b/test/functional/legacy/101_hlsearch_spec.lua @@ -61,6 +61,6 @@ describe('v:hlsearch', function() 0:not highlighted 1:highlighted 0:not highlighted - Vim(let):E706:]]) + Vim(let):E745:]]) end) end) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 8da6ee45d7..42dd25023a 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -64,6 +64,20 @@ describe('assert function:', function() end) end) + -- assert_notequal({expected}, {actual}[, {msg}]) + describe('assert_notequal', function() + it('should not change v:errors when expected differs from actual', function() + call('assert_notequal', 'foo', 4) + call('assert_notequal', {1, 2, 3}, 'foo') + expected_empty() + end) + + it('should change v:errors when expected is equal to actual', function() + call('assert_notequal', 'foo', 'foo') + expected_errors({"Expected 'foo' differs from 'foo'"}) + end) + end) + -- assert_false({actual}, [, {msg}]) describe('assert_false', function() it('should not change v:errors when actual is false', function() @@ -155,10 +169,43 @@ describe('assert function:', function() end) end) + -- assert_match({pat}, {text}[, {msg}]) + describe('assert_match', function() + it('should not change v:errors when pat matches text', function() + call('assert_match', '^f.*b.*r$', 'foobar') + expected_empty() + end) + + it('should change v:errors when pat does not match text', function() + call('assert_match', 'bar.*foo', 'foobar') + expected_errors({"Pattern 'bar.*foo' does not match 'foobar'"}) + end) + + it('should set v:errors to msg when given and match fails', function() + call('assert_match', 'bar.*foo', 'foobar', 'wrong') + expected_errors({"'wrong'"}) + end) + end) + + -- assert_notmatch({pat}, {text}[, {msg}]) + describe('assert_notmatch', function() + it('should not change v:errors when pat does not match text', function() + call('assert_notmatch', 'foo', 'bar') + call('assert_notmatch', '^foobar$', 'foobars') + expected_empty() + end) + + it('should change v:errors when pat matches text', function() + call('assert_notmatch', 'foo', 'foobar') + expected_errors({"Pattern 'foo' does match 'foobar'"}) + end) + end) + -- assert_fails({cmd}, [, {error}]) describe('assert_fails', function() it('should change v:errors when error does not match v:errmsg', function() execute([[call assert_fails('xxx', {})]]) + execute([[call assert_match("Expected {} but got 'E731:", v:errors[0])]]) expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"}) end) diff --git a/test/functional/legacy/writefile_spec.lua b/test/functional/legacy/writefile_spec.lua index f096aa23b9..765d373b82 100644 --- a/test/functional/legacy/writefile_spec.lua +++ b/test/functional/legacy/writefile_spec.lua @@ -17,6 +17,7 @@ describe('writefile', function() execute('bwipeout!') execute('$put =readfile(f)') execute('1 delete _') + execute('call delete(f)') -- Assert buffer contents. expect([[ diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua new file mode 100644 index 0000000000..7b0e17688d --- /dev/null +++ b/test/functional/provider/ruby_spec.lua @@ -0,0 +1,96 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local feed = helpers.feed +local clear = helpers.clear +local funcs = helpers.funcs +local meths = helpers.meths +local insert = helpers.insert +local expect = helpers.expect +local command = helpers.command +local write_file = helpers.write_file +local curbufmeths = helpers.curbufmeths + +do + clear() + command('let g:prog = provider#ruby#Detect()') + local prog = meths.get_var('prog') + + if prog == '' then + pending( + "Cannot find the neovim RubyGem. Try :CheckHealth", + function() end) + return + end +end + +before_each(function() + clear() +end) + +describe('ruby feature test', function() + it('works', function() + eq(1, funcs.has('ruby')) + end) +end) + +describe(':ruby command', function() + it('evaluates ruby', function() + command('ruby VIM.command("let g:set_by_ruby = [100, 0]")') + eq({100, 0}, meths.get_var('set_by_ruby')) + end) + + it('supports nesting', function() + command([[ruby VIM.command('ruby VIM.command("let set_by_nested_ruby = 555")')]]) + eq(555, meths.get_var('set_by_nested_ruby')) + end) +end) + +describe(':rubyfile command', function() + it('evaluates a ruby file', function() + local fname = 'rubyfile.rb' + write_file(fname, 'VIM.command("let set_by_rubyfile = 123")') + command('rubyfile rubyfile.rb') + eq(123, meths.get_var('set_by_rubyfile')) + os.remove(fname) + end) +end) + +describe(':rubydo command', function() + it('exposes the $_ variable for modifying lines', function() + insert('abc\ndef\nghi\njkl') + expect([[ + abc + def + ghi + jkl]]) + + feed('ggjvj:rubydo $_.upcase!<CR>') + expect([[ + abc + DEF + GHI + jkl]]) + end) + + it('operates on all lines when not given a range', function() + insert('abc\ndef\nghi\njkl') + expect([[ + abc + def + ghi + jkl]]) + + feed(':rubydo $_.upcase!<CR>') + expect([[ + ABC + DEF + GHI + JKL]]) + end) + + it('does not modify the buffer if no changes are made', function() + command('normal :rubydo 42') + eq(false, curbufmeths.get_option('modified')) + end) +end) diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index a433143266..7b820347ac 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -462,4 +462,321 @@ describe('Mouse input', function() | ]]) end) + + describe('on concealed text', function() + -- Helpful for reading the test expectations: + -- :match Error /\^/ + local concealed = { + c = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray } + } + + before_each(function() + screen:try_resize(25, 7) + feed('ggdG') + + execute('set concealcursor=n') + execute('set nowrap') + execute('syntax match NonText "\\<amet\\>" conceal') + execute('syntax match NonText "\\cs\\|g." conceal cchar=X') + execute('syntax match NonText "\\%(lo\\|cl\\)." conceal') + execute('syntax match NonText "Lo" conceal cchar=Y') + + insert([[ + Lorem ipsum dolor sit amet, consetetur sadipscing elitr. + Stet clita kasd gubergren, no sea takimata sanctus est. + ]]) + + feed('gg') + end) + + it('(level 1) click on non-wrapped lines', function() + execute('let &conceallevel=1', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + {c:^Y}rem ip{c:X}um do{c: } {c:X}it {c: }, con| + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en, no| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><1,0>') + screen:expect([[ + {c:Y}^rem ip{c:X}um do{c: } {c:X}it {c: }, con| + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en, no| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,0>') + screen:expect([[ + {c:Y}rem ip{c:X}um do{c: } {c:^X}it {c: }, con| + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en, no| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do{c: } {c:X}it {c: }, con| + {c:X}tet {c: }ta ka{c:X}d {c:X}^ber{c:X}en, no| + | + ~ | + ~ | + ~ | + | + ]], concealed) + end) -- level 1 - non wrapped + + it('(level 1) click on wrapped lines', function() + execute('let &conceallevel=1', 'let &wrap=1', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + {c:^Y}rem ip{c:X}um do{c: } {c:X}it {c: } | + , con{c:X}etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><6,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do{c: } {c:X}it {c: } | + , con{c:X}^etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do{c: } {c:X}it {c: } | + , con{c:X}etetur {c:X}a^dip{c:X}cin{c:X} | + elitr. | + {c:X}tet {c: }ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,3>') + screen:expect([[ + {c:Y}rem ip{c:X}um do{c: } {c:X}it {c: } | + , con{c:X}etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet {c: }ta ka{c:X}d {c:X}^ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + end) -- level 1 - wrapped + + + it('(level 2) click on non-wrapped lines', function() + execute('let &conceallevel=2', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + {c:^Y}rem ip{c:X}um do {c:X}it , con{c:X}e| + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en, no | + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><1,0>') + screen:expect([[ + {c:Y}^rem ip{c:X}um do {c:X}it , con{c:X}e| + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en, no | + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,0>') + screen:expect([[ + {c:Y}rem ip{c:X}um do {c:X}^it , con{c:X}e| + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en, no | + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do {c:X}it , con{c:X}e| + {c:X}tet ta ka{c:X}d {c:X}b^er{c:X}en, no | + | + ~ | + ~ | + ~ | + | + ]], concealed) + end) -- level 2 - non wrapped + + it('(level 2) click on wrapped lines', function() + execute('let &conceallevel=2', 'let &wrap=1', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + {c:^Y}rem ip{c:X}um do {c:X}it | + , con{c:X}etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><6,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do {c:X}it | + , con{c:X}^etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + {c:Y}rem ip{c:X}um do {c:X}it | + , con{c:X}etetur {c:X}a^dip{c:X}cin{c:X} | + elitr. | + {c:X}tet ta ka{c:X}d {c:X}ber{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,3>') + screen:expect([[ + {c:Y}rem ip{c:X}um do {c:X}it | + , con{c:X}etetur {c:X}adip{c:X}cin{c:X} | + elitr. | + {c:X}tet ta ka{c:X}d {c:X}b^er{c:X}en | + , no {c:X}ea takimata {c:X}anctu{c:X}| + e{c:X}t. | + | + ]], concealed) + end) -- level 2 - wrapped + + + it('(level 3) click on non-wrapped lines', function() + execute('let &conceallevel=3', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + ^rem ipum do it , conetetu| + tet ta kad beren, no ea t| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><1,0>') + screen:expect([[ + r^em ipum do it , conetetu| + tet ta kad beren, no ea t| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,0>') + screen:expect([[ + rem ipum do it ^, conetetu| + tet ta kad beren, no ea t| + | + ~ | + ~ | + ~ | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + rem ipum do it , conetetu| + tet ta kad bere^n, no ea t| + | + ~ | + ~ | + ~ | + | + ]], concealed) + end) -- level 3 - non wrapped + + it('(level 3) click on wrapped lines', function() + execute('let &conceallevel=3', 'let &wrap=1', 'echo') + + feed('<esc><LeftMouse><0,0>') + screen:expect([[ + ^rem ipum do it | + , conetetur adipcin | + elitr. | + tet ta kad beren | + , no ea takimata anctu | + et. | + | + ]], concealed) + + feed('<esc><LeftMouse><6,1>') + screen:expect([[ + rem ipum do it | + , cone^tetur adipcin | + elitr. | + tet ta kad beren | + , no ea takimata anctu | + et. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,1>') + screen:expect([[ + rem ipum do it | + , conetetur adi^pcin | + elitr. | + tet ta kad beren | + , no ea takimata anctu | + et. | + | + ]], concealed) + + feed('<esc><LeftMouse><15,3>') + screen:expect([[ + rem ipum do it | + , conetetur adipcin | + elitr. | + tet ta kad bere^n | + , no ea takimata anctu | + et. | + | + ]], concealed) + end) -- level 3 - wrapped + end) end) diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua new file mode 100644 index 0000000000..c7c8986527 --- /dev/null +++ b/test/functional/ui/output_spec.lua @@ -0,0 +1,39 @@ +local session = require('test.functional.helpers')(after_each) +local child_session = require('test.functional.terminal.helpers') + +describe("shell command :!", function() + local screen + before_each(function() + session.clear() + screen = child_session.screen_setup(0, '["'..session.nvim_prog.. + '", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile"]') + screen:expect([[ + {1: } | + ~ | + ~ | + ~ | + [No Name] | + | + -- TERMINAL -- | + ]]) + end) + + after_each(function() + screen:detach() + end) + + it("displays output even without LF/EOF. #4646 #4569 #3772", function() + -- NOTE: We use a child nvim (within a :term buffer) + -- to avoid triggering a UI flush. + child_session.feed_data(":!printf foo; sleep 200\n") + screen:expect([[ + ~ | + ~ | + [No Name] | + :!printf foo; sleep 200 | + | + foo | + -- TERMINAL -- | + ]]) + end) +end) |