aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/server_requests_spec.lua44
-rw-r--r--test/functional/clipboard/clipboard_provider_spec.lua14
-rw-r--r--test/functional/ex_cmds/recover_spec.lua71
-rw-r--r--test/functional/helpers.lua11
-rw-r--r--test/functional/job/job_spec.lua49
-rw-r--r--test/functional/legacy/038_virtual_replace_spec.lua58
-rw-r--r--test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua147
-rw-r--r--test/functional/legacy/051_highlight_spec.lua6
-rw-r--r--test/functional/legacy/078_swapfile_recover_spec.lua80
-rw-r--r--test/functional/server/server_spec.lua42
-rw-r--r--test/functional/shell/viml_system_spec.lua4
-rw-r--r--test/functional/terminal/buffer_spec.lua43
-rw-r--r--test/functional/terminal/cursor_spec.lua6
-rw-r--r--test/functional/terminal/helpers.lua2
-rw-r--r--test/functional/terminal/mouse_spec.lua14
-rw-r--r--test/unit/os/env_spec.lua17
-rw-r--r--test/unit/path_spec.lua7
17 files changed, 596 insertions, 19 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index a37c41294b..34669c5f29 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -3,8 +3,8 @@
-- be running.
local helpers = require('test.functional.helpers')
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
-local eq, run, stop = helpers.eq, helpers.run, helpers.stop
-
+local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
+local nvim_prog = helpers.nvim_prog
describe('server -> client', function()
@@ -115,4 +115,44 @@ describe('server -> client', function()
eq(expected, notified)
end)
end)
+
+ describe('when the client is a recursive vim instance', function()
+ before_each(function()
+ nvim('command', "let vim = rpcstart('"..nvim_prog.."', ['--embed'])")
+ neq(0, eval('vim'))
+ end)
+
+ after_each(function() nvim('command', 'call rpcstop(vim)') end)
+
+ it('can send/recieve notifications and make requests', function()
+ nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')")
+
+ -- Wait for the notification to complete.
+ nvim('command', "call rpcrequest(vim, 'vim_eval', '0')")
+
+ eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')"))
+ end)
+
+ it('can communicate buffers, tabpages, and windows', function()
+ eq({3}, eval("rpcrequest(vim, 'vim_get_tabpages')"))
+ eq({1}, eval("rpcrequest(vim, 'vim_get_windows')"))
+
+ local buf = eval("rpcrequest(vim, 'vim_get_buffers')")[1]
+ eq(2, buf)
+
+ eval("rpcnotify(vim, 'buffer_set_line', "..buf..", 0, 'SOME TEXT')")
+ nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait
+
+ eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)"))
+
+ -- Call get_line_slice(buf, range [0,0], includes start, includes end)
+ eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_line_slice', "..buf..", 0, 0, 1, 1)"))
+ end)
+
+ it('returns an error if the request failed', function()
+ local status, err = pcall(eval, "rpcrequest(vim, 'does-not-exist')")
+ eq(false, status)
+ eq(true, string.match(err, ': (.*)') == 'Failed to evaluate expression')
+ end)
+ end)
end)
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua
index e7ca183a0e..c5d8f57008 100644
--- a/test/functional/clipboard/clipboard_provider_spec.lua
+++ b/test/functional/clipboard/clipboard_provider_spec.lua
@@ -55,6 +55,12 @@ local function basic_register_test(noblock)
, stuff and some more
some textsome some text, stuff and some more]])
+ -- deleting a line does update ""
+ feed('ggdd""P')
+ expect([[
+ , stuff and some more
+ some textsome some text, stuff and some more]])
+
feed('ggw<c-v>jwyggP')
if noblock then
expect([[
@@ -72,6 +78,7 @@ end
describe('the unnamed register', function()
before_each(clear)
it('works without provider', function()
+ eq('"', eval('v:register'))
basic_register_test()
end)
end)
@@ -227,6 +234,13 @@ describe('clipboard usage', function()
a line]])
end)
+ it('supports v:register and getreg() without parameters', function()
+ eq('*', eval('v:register'))
+ execute("let g:test_clip['*'] = [['some block',''], 'b']")
+ eq('some block', eval('getreg()'))
+ eq('\02210', eval('getregtype()'))
+ end)
+
end)
it('supports :put', function()
diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua
new file mode 100644
index 0000000000..d4c9477133
--- /dev/null
+++ b/test/functional/ex_cmds/recover_spec.lua
@@ -0,0 +1,71 @@
+-- Tests for :recover
+
+local helpers = require('test.functional.helpers')
+local execute, eq, clear, eval, feed, expect, source =
+ helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.feed,
+ helpers.expect, helpers.source
+
+describe(':recover', function()
+ before_each(clear)
+
+ it('fails if given a non-existent swapfile', function()
+ local swapname = 'bogus-swapfile'
+ execute('recover '..swapname) -- This should not segfault. #2117
+ eq('E305: No swap file found for '..swapname, eval('v:errmsg'))
+ end)
+
+end)
+
+describe(':preserve', function()
+ local swapdir = lfs.currentdir()..'/testdir_recover_spec'
+ before_each(function()
+ clear()
+ os.remove(swapdir)
+ lfs.mkdir(swapdir)
+ end)
+ after_each(function()
+ os.remove(swapdir)
+ end)
+
+ it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()
+ local testfile = 'testfile_recover_spec'
+ local init = [[
+ set swapfile fileformat=unix undolevels=-1
+ set directory^=]]..swapdir..[[//
+ ]]
+
+ source(init)
+ execute('set swapfile fileformat=unix undolevels=-1')
+ -- Put swapdir at the start of the 'directory' list. #1836
+ execute('set directory^='..swapdir..'//')
+ execute('edit '..testfile)
+ feed('isometext<esc>')
+ execute('preserve')
+ source('redir => g:swapname | swapname | redir END')
+
+ local swappath1 = eval('g:swapname')
+
+ --TODO(justinmk): this is an ugly hack to force `helpers` to support
+ --multiple sessions.
+ local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '--embed'})
+ helpers.set_session(nvim2)
+
+ source(init)
+
+ -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
+ execute('autocmd SwapExists * let v:swapchoice = "r"')
+ execute('silent edit '..testfile)
+ source('redir => g:swapname | swapname | redir END')
+
+ local swappath2 = eval('g:swapname')
+
+ -- swapfile from session 1 should end in .swp
+ assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$'))
+
+ -- swapfile from session 2 should end in .swo
+ assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$'))
+
+ expect('sometext')
+ end)
+
+end)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 393b42dda5..27c94c34a8 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -18,6 +18,10 @@ if nvim_dir == nvim_prog then
nvim_dir = "."
end
+-- Nvim "Unit Under Test" http://en.wikipedia.org/wiki/Device_under_test
+local NvimUUT = {}
+NvimUUT.__index = NvimUUT
+
local prepend_argv
if os.getenv('VALGRIND') then
@@ -49,6 +53,10 @@ end
local session, loop_running, loop_stopped, last_error
+local function set_session(s)
+ session = s
+end
+
local function request(method, ...)
local status, rv = session:request(method, ...)
if not status then
@@ -305,5 +313,6 @@ return {
curwin = curwin,
curtab = curtab,
curbuf_contents = curbuf_contents,
- wait = wait
+ wait = wait,
+ set_session = set_session
}
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua
index c517ae4c1b..df989b3ef9 100644
--- a/test/functional/job/job_spec.lua
+++ b/test/functional/job/job_spec.lua
@@ -61,7 +61,6 @@ describe('jobs', function()
file:write("abc\0def\n")
file:close()
- -- v:job_data preserves NULs.
nvim('command', "let j = jobstart(['cat', '"..filename.."'], g:job_opts)")
eq({'notification', 'stdout', {0, {'abc\ndef', ''}}}, next_msg())
eq({'notification', 'exit', {0, 0}}, next_msg())
@@ -249,6 +248,52 @@ describe('jobs', function()
eq({'notification', 'wait', {{-2}}}, next_msg())
end)
+ it('can be called recursively', function()
+ source([[
+ let g:opts = {}
+ let g:counter = 0
+ function g:opts.on_stdout(id, msg)
+ if self.state == 0
+ if self.counter < 10
+ call Run()
+ endif
+ let self.state = 1
+ call jobsend(a:id, "line1\n")
+ elseif self.state == 1
+ let self.state = 2
+ call jobsend(a:id, "line2\n")
+ elseif self.state == 2
+ let self.state = 3
+ call jobsend(a:id, "line3\n")
+ else
+ call rpcnotify(g:channel, 'w', printf('job %d closed', self.counter))
+ call jobclose(a:id, 'stdin')
+ endif
+ endfunction
+ function g:opts.on_exit()
+ call rpcnotify(g:channel, 'w', printf('job %d exited', self.counter))
+ endfunction
+ function Run()
+ let g:counter += 1
+ let j = copy(g:opts)
+ let j.state = 0
+ let j.counter = g:counter
+ call jobwait([
+ \ jobstart([&sh, '-c', 'echo ready; cat -'], j),
+ \ ])
+ endfunction
+ ]])
+ execute('call Run()')
+ local r
+ for i = 10, 1, -1 do
+ r = next_msg()
+ eq('job '..i..' closed', r[3][1])
+ r = next_msg()
+ eq('job '..i..' exited', r[3][1])
+ end
+ eq(10, nvim('eval', 'g:counter'))
+ end)
+
describe('with timeout argument', function()
it('will return -1 if the wait timed out', function()
source([[
@@ -292,7 +337,7 @@ describe('jobs', function()
data[i] = data[i]:gsub('\n', '\000')
end
rv = table.concat(data, '\n')
- rv = rv:gsub('\r\n$', '')
+ rv = rv:gsub('\r\n$', ''):gsub('^\r\n', '')
if rv ~= '' then
break
end
diff --git a/test/functional/legacy/038_virtual_replace_spec.lua b/test/functional/legacy/038_virtual_replace_spec.lua
new file mode 100644
index 0000000000..239ffa47e6
--- /dev/null
+++ b/test/functional/legacy/038_virtual_replace_spec.lua
@@ -0,0 +1,58 @@
+-- Test Virtual replace mode.
+
+local helpers = require('test.functional.helpers')
+local feed, insert, source = helpers.feed, helpers.insert, helpers.source
+local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
+
+describe('Virtual replace mode', function()
+ setup(clear)
+
+ it('is working', function()
+ -- Make sure that backspace works, no matter what termcap is used.
+ execute('set t_kD=x7f t_kb=x08')
+ feed('ggdGa<cr>')
+ feed('abcdefghi<cr>')
+ feed('jk<tab>lmn<cr>')
+ feed('<Space><Space><Space><Space>opq<tab>rst<cr>')
+ feed('<C-d>uvwxyz<cr>')
+ feed('<esc>gg')
+ execute('set ai')
+ execute('set bs=2')
+ feed('gR0<C-d> 1<cr>')
+ feed('A<cr>')
+ feed('BCDEFGHIJ<cr>')
+ feed('<tab>KL<cr>')
+ feed('MNO<cr>')
+ feed('PQR<esc>G')
+ execute('ka')
+ feed('o0<C-d><cr>')
+ feed('abcdefghi<cr>')
+ feed('jk<tab>lmn<cr>')
+ feed('<Space><Space><Space><Space>opq<tab>rst<cr>')
+ feed('<C-d>uvwxyz<cr>')
+ feed([[<esc>'ajgR0<C-d> 1<cr>]])
+ feed('A<cr>')
+ feed('BCDEFGHIJ<cr>')
+ feed('<tab>KL<cr>')
+ feed('MNO<cr>')
+ feed('PQR<C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><C-h><esc>:$<cr>')
+ feed('iab<tab>cdefghi<tab>jkl<esc>0gRAB......CDEFGHI.J<esc>o<esc>:<cr>')
+ feed('iabcdefghijklmnopqrst<esc>0gRAB<tab>IJKLMNO<tab>QR<esc>')
+
+ -- Assert buffer contents.
+ expect([=[
+ 1
+ A
+ BCDEFGHIJ
+ KL
+ MNO
+ PQR
+ 1
+ abcdefghi
+ jk lmn
+ opq rst
+ uvwxyz
+ AB......CDEFGHI.Jkl
+ AB IJKLMNO QRst]=])
+ end)
+end)
diff --git a/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua
new file mode 100644
index 0000000000..de628b0b52
--- /dev/null
+++ b/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua
@@ -0,0 +1,147 @@
+-- Tests for regexp with multi-byte encoding and various magic settings.
+-- Test matchstr() with a count and multi-byte chars.
+--
+-- This test contains both "test44" and "test99" from the old test suite.
+
+local helpers = require('test.functional.helpers')
+local feed, insert, source = helpers.feed, helpers.insert, helpers.source
+local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
+
+-- Runs the test protocol with the given 'regexpengine' setting. In the old test
+-- suite the test protocol was duplicated in test44 and test99, the only
+-- difference being the 'regexpengine' setting. We've extracted it here.
+local function run_test_with_regexpengine(regexpengine)
+ insert([[
+ 1 a aa abb abbccc
+ 2 d dd dee deefff
+ 3 g gg ghh ghhiii
+ 4 j jj jkk jkklll
+ 5 m mm mnn mnnooo
+ 6 x ^aa$ x
+ 7 (a)(b) abbaa
+ 8 axx [ab]xx
+ 9 หม่x อมx
+ a อมx หม่x
+ b ちカヨは
+ c x ¬€x
+ d 天使x
+ e y
+ f z
+ g a啷bb
+ h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐẔ
+ i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ
+ j 0123❤x
+ k combinations]])
+
+ execute('set encoding=utf-8 termencoding=latin1')
+ execute('set re=' .. regexpengine)
+
+ -- Lines 1-8. Exercise regexp search with various magic settings. On each
+ -- line the character on which the cursor is expected to land is deleted.
+ feed('/^1<cr>')
+ feed([[/a*b\{2}c\+/e<cr>x]])
+ feed([[/\Md\*e\{2}f\+/e<cr>x]])
+ execute('set nomagic')
+ feed([[/g\*h\{2}i\+/e<cr>x]])
+ feed([[/\mj*k\{2}l\+/e<cr>x]])
+ feed([[/\vm*n{2}o+/e<cr>x]])
+ feed([[/\V^aa$<cr>x]])
+ execute('set magic')
+ feed([[/\v(a)(b)\2\1\1/e<cr>x]])
+ feed([[/\V[ab]\(\[xy]\)\1<cr>x]])
+
+ -- Line 9. Search for multi-byte character without combining character.
+ feed('/ม<cr>x')
+
+ -- Line a. Search for multi-byte character with combining character.
+ feed('/ม่<cr>x')
+
+ -- Line b. Find word by change of word class.
+ -- (The "<" character in this test step seemed to confuse our "feed" test
+ -- helper, which is why we've resorted to "execute" here.)
+ execute([[/ち\<カヨ\>は]])
+ feed('x')
+
+ -- Lines c-i. Test \%u, [\u], and friends.
+ feed([[/\%u20ac<cr>x]])
+ feed([[/[\u4f7f\u5929]\+<cr>x]])
+ feed([[/\%U12345678<cr>x]])
+ feed([[/[\U1234abcd\u1234\uabcd]<cr>x]])
+ feed([[/\%d21879b<cr>x]])
+ feed('/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* ' ..
+ '[[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* ' ..
+ '[[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* ' ..
+ '[[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e<cr>x')
+ feed('/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* ' ..
+ '[[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* ' ..
+ '[[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* ' ..
+ '[[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e<cr>x')
+
+ -- Line j. Test backwards search from a multi-byte character.
+ feed('/x<cr>x')
+ feed('?.<cr>x')
+
+ -- Line k. Test substitution with combining characters by executing register
+ -- contents.
+ execute([[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']])
+ execute('@w')
+
+ -- Additional tests. Test matchstr() with multi-byte characters.
+ feed('G')
+ execute([[put =matchstr(\"אבגד\", \".\", 0, 2)]]) -- ב
+ execute([[put =matchstr(\"אבגד\", \"..\", 0, 2)]]) -- בג
+ execute([[put =matchstr(\"אבגד\", \".\", 0, 0)]]) -- א
+ execute([[put =matchstr(\"אבגד\", \".\", 4, -1)]]) -- ג
+
+ -- Test that a search with "/e" offset wraps around at the end of the buffer.
+ execute('new')
+ execute([[$put =['dog(a', 'cat('] ]])
+ feed('/(/e+<cr>')
+ feed('"ayn')
+ execute('bd!')
+ execute([[$put ='']])
+ feed('G"ap')
+
+ -- Assert buffer contents.
+ expect([[
+ 1 a aa abb abbcc
+ 2 d dd dee deeff
+ 3 g gg ghh ghhii
+ 4 j jj jkk jkkll
+ 5 m mm mnn mnnoo
+ 6 x aa$ x
+ 7 (a)(b) abba
+ 8 axx ab]xx
+ 9 หม่x อx
+ a อมx หx
+ b カヨは
+ c x ¬x
+ d 使x
+ e y
+ f z
+ g abb
+ h AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐ
+ i aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑ
+ j 012❤
+ k œ̄ṣ́m̥̄ᾱ̆́
+ ב
+ בג
+ א
+ ג
+ a
+ cat(]])
+end
+
+describe('multi-byte regexp search with magic settings', function()
+ before_each(clear)
+
+ it('is working with regexpengine=1', function()
+ -- The old test44.
+ run_test_with_regexpengine(1)
+ end)
+
+ it('is working with regexpengine=2', function()
+ -- The old test99.
+ run_test_with_regexpengine(2)
+ end)
+end)
diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua
index 3d0375312d..620df97aac 100644
--- a/test/functional/legacy/051_highlight_spec.lua
+++ b/test/functional/legacy/051_highlight_spec.lua
@@ -24,10 +24,10 @@ describe(':highlight', function()
guifg=Blue |
EndOfBuffer xxx links to NonText|
|
+ TermCursor xxx cterm=reverse |
+ gui=reverse |
+ TermCursorNC xxx cleared |
NonText xxx ctermfg=12 |
- gui=bold |
- guifg=Blue |
- Directory xxx ctermfg=4 |
-- More --^ |
]])
feed('q')
diff --git a/test/functional/legacy/078_swapfile_recover_spec.lua b/test/functional/legacy/078_swapfile_recover_spec.lua
new file mode 100644
index 0000000000..e250c91441
--- /dev/null
+++ b/test/functional/legacy/078_swapfile_recover_spec.lua
@@ -0,0 +1,80 @@
+-- Inserts 10000 lines with text to fill the swap file with two levels of
+-- pointer blocks. Then recovers from the swap file and checks all text is
+-- restored. We need about 10000 lines of 100 characters to get two levels of
+-- pointer blocks.
+
+local helpers = require('test.functional.helpers')
+local feed, insert, source = helpers.feed, helpers.insert, helpers.source
+local clear, execute, expect, source = helpers.clear, helpers.execute, helpers.expect, helpers.source
+local eval = helpers.eval
+
+describe('78', function()
+ setup(clear)
+ teardown(function()
+ os.remove(".Xtest.swp")
+ os.remove(".Xtest.swo")
+ end)
+
+ it('is working', function()
+ source([=[
+ set swapfile fileformat=unix undolevels=-1
+ e! Xtest
+ let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789"
+ let i = 1
+ let linecount = 10000
+ while i <= linecount | call append(i - 1, i . text) | let i += 1 | endwhile
+ preserve
+
+ " Get the name of the swap file, and clean up the :redir capture.
+ redir => g:swapname | swapname | redir END
+ let g:swapname = substitute(g:swapname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', 'g')
+ let g:swapname = fnameescape(g:swapname)
+
+ " Make a copy of the swap file in Xswap
+ set bin
+ exe 'sp ' . g:swapname
+ w! Xswap
+
+ set nobin
+ new
+ only!
+ bwipe! Xtest
+ call rename('Xswap', g:swapname)
+
+ "TODO(jkeyes): without 'silent', this hangs the test " at message:
+ " 'Recovery completed. You should check if everything is OK.'
+ silent recover Xtest
+
+ call delete(g:swapname)
+ new
+ call append(0, 'recovery start')
+ wincmd w
+
+ let g:linedollar = line('$')
+ if g:linedollar < linecount
+ wincmd w
+ call append(line('$'), "expected " . linecount
+ \ . " lines but found only " . g:linedollar)
+ wincmd w
+ let linecount = g:linedollar
+ endif
+
+ let i = 1
+ while i <= linecount
+ if getline(i) != i . text
+ exe 'wincmd w'
+ call append(line('$'), i . ' differs')
+ exe 'wincmd w'
+ endif
+ let i += 1
+ endwhile
+ q!
+ call append(line('$'), 'recovery end')
+ ]=])
+
+ expect([[
+ recovery start
+
+ recovery end]])
+ end)
+end)
diff --git a/test/functional/server/server_spec.lua b/test/functional/server/server_spec.lua
new file mode 100644
index 0000000000..5dd8197d52
--- /dev/null
+++ b/test/functional/server/server_spec.lua
@@ -0,0 +1,42 @@
+
+local helpers = require('test.functional.helpers')
+local nvim, eq, neq, ok, eval
+ = helpers.nvim, helpers.eq, helpers.neq, helpers.ok, helpers.eval
+local clear = helpers.clear
+
+describe('server*() functions', function()
+ before_each(clear)
+
+ it('set $NVIM_LISTEN_ADDRESS on first serverstart()', function()
+ -- Ensure the listen address is unset.
+ nvim('command', 'let $NVIM_LISTEN_ADDRESS = ""')
+ nvim('command', 'let s = serverstart()')
+ eq(1, eval('$NVIM_LISTEN_ADDRESS == s'))
+ nvim('command', 'call serverstop(s)')
+ eq(0, eval('$NVIM_LISTEN_ADDRESS == s'))
+ end)
+
+ it('let the user retrieve the list of servers', function()
+ -- There should already be at least one server.
+ local n = eval('len(serverlist())')
+
+ -- Add a few
+ local servs = {'should-not-exist', 'another-one-that-shouldnt'}
+ for _, s in ipairs(servs) do
+ eq(s, eval('serverstart("'..s..'")'))
+ end
+
+ local new_servs = eval('serverlist()')
+
+ -- Exactly #servs servers should be added.
+ eq(n + #servs, #new_servs)
+ -- The new servers should be at the end of the list.
+ for i = 1, #servs do
+ eq(servs[i], new_servs[i + n])
+ nvim('command', 'call serverstop("'..servs[i]..'")')
+ end
+ -- After calling serverstop() on the new servers, they should no longer be
+ -- in the list.
+ eq(n, eval('len(serverlist())'))
+ end)
+end)
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua
index c9ae92048c..922770ad42 100644
--- a/test/functional/shell/viml_system_spec.lua
+++ b/test/functional/shell/viml_system_spec.lua
@@ -110,7 +110,7 @@ describe('system()', function()
~ |
~ |
~ |
- Type :quit<Enter> to exit Vim |
+ Type :quit<Enter> to exit Nvim |
]])
end)
end)
@@ -276,7 +276,7 @@ describe('systemlist()', function()
~ |
~ |
~ |
- Type :quit<Enter> to exit Vim |
+ Type :quit<Enter> to exit Nvim |
]])
end)
end)
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 857679c4b3..ffdfec4428 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -2,7 +2,9 @@ local helpers = require('test.functional.helpers')
local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
-local wait, execute, eq = helpers.wait, helpers.execute, helpers.eq
+local wait = helpers.wait
+local eval, execute, source = helpers.eval, helpers.execute, helpers.source
+local eq, neq = helpers.eq, helpers.neq
describe('terminal buffer', function()
@@ -155,5 +157,44 @@ describe('terminal buffer', function()
:bnext |
]])
end)
+
+ it('handles loss of focus gracefully', function()
+ -- Temporarily change the statusline to avoid printing the file name, which
+ -- varies be where the test is run.
+ nvim('set_option', 'statusline', '==========')
+ execute('set laststatus=0')
+
+ -- Save the buffer number of the terminal for later testing.
+ local tbuf = eval('bufnr("%")')
+
+ source([[
+ function! SplitWindow()
+ new
+ call feedkeys("iabc\<Esc>")
+ endfunction
+
+ startinsert
+ call jobstart(['sh', '-c', 'exit'], {'on_exit': function("SplitWindow")})
+ call feedkeys("\<C-\>", 't') " vim will expect <C-n>, but be exited out of
+ " the terminal before it can be entered.
+ ]])
+
+ -- We should be in a new buffer now.
+ screen:expect([[
+ ab^c |
+ ~ |
+ ========== |
+ rows: 2, cols: 50 |
+ {2: } |
+ {1:========== }|
+ |
+ ]])
+
+ neq(tbuf, eval('bufnr("%")'))
+ execute('quit!') -- Should exit the new window, not the terminal.
+ eq(tbuf, eval('bufnr("%")'))
+
+ execute('set laststatus=1') -- Restore laststatus to the default.
+ end)
end)
diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua
index 3e3f9cbf4f..cecb33de7c 100644
--- a/test/functional/terminal/cursor_spec.lua
+++ b/test/functional/terminal/cursor_spec.lua
@@ -129,10 +129,8 @@ describe('cursor with customized highlighting', function()
before_each(function()
clear()
- nvim('set_var', 'terminal_focused_cursor_highlight', 'CursorFocused')
- nvim('set_var', 'terminal_unfocused_cursor_highlight', 'CursorUnfocused')
- nvim('command', 'highlight CursorFocused ctermfg=45 ctermbg=46')
- nvim('command', 'highlight CursorUnfocused ctermfg=55 ctermbg=56')
+ nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE')
+ nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE')
screen = Screen.new(50, 7)
screen:set_default_attr_ids({
[1] = {foreground = 45, background = 46},
diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua
index 631dc579d3..1bc6057a0b 100644
--- a/test/functional/terminal/helpers.lua
+++ b/test/functional/terminal/helpers.lua
@@ -34,6 +34,8 @@ local function disable_mouse() feed_termcode('[?1002l') end
local function screen_setup(extra_height)
+ nvim('command', 'highlight TermCursor cterm=reverse')
+ nvim('command', 'highlight TermCursorNC ctermbg=11')
nvim('set_var', 'terminal_scrollback_buffer_size', 10)
if not extra_height then extra_height = 0 end
local screen = Screen.new(50, 7 + extra_height)
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index b8f6214f8f..4def4dd7f8 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -50,6 +50,20 @@ describe('terminal mouse', function()
]])
end)
+ it('will exit focus after <C-\\>, then scrolled', function()
+ feed('<C-\\>')
+ feed('<MouseDown><0,0>')
+ screen:expect([[
+ line23 |
+ line24 |
+ line25 |
+ line26 |
+ line27 |
+ ^line28 |
+ |
+ ]])
+ end)
+
describe('with mouse events enabled by the program', function()
before_each(function()
thelpers.enable_mouse()
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index 5896f5ddd4..9d936c2564 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -3,6 +3,7 @@ local helpers = require('test.unit.helpers')
local cimport = helpers.cimport
local internalize = helpers.internalize
local eq = helpers.eq
+local neq = helpers.neq
local ffi = helpers.ffi
local lib = helpers.lib
local cstr = helpers.cstr
@@ -21,6 +22,10 @@ describe('env function', function()
return env.os_setenv((to_cstr(name)), (to_cstr(value)), override)
end
+ function os_unsetenv(name, value, override)
+ return env.os_unsetenv((to_cstr(name)))
+ end
+
function os_getenv(name)
local rval = env.os_getenv((to_cstr(name)))
if rval ~= NULL then
@@ -68,6 +73,18 @@ describe('env function', function()
end)
end)
+ describe('os_unsetenv', function()
+ it('unsets environment variable', function()
+ local name = 'TEST_UNSETENV'
+ local value = 'TESTVALUE'
+ os_setenv(name, value, 1)
+ os_unsetenv(name)
+ neq(os_getenv(name), value)
+ -- Depending on the platform the var might be unset or set as ''
+ assert.True(os_getenv(name) == nil or os_getenv(name) == '')
+ end)
+ end)
+
describe('os_getenvname_at_index', function()
it('returns names of environment variables', function()
local test_name = 'NEOVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1N'
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index 13546a6183..261d797624 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -425,19 +425,18 @@ describe('more path function', function()
return ffi.string(c_file)
end
+ before_each(function() lfs.mkdir('CamelCase') end)
+ after_each(function() lfs.rmdir('CamelCase') end)
+
if ffi.os == 'Windows' or ffi.os == 'OSX' then
it('Corrects the case of file names in Mac and Windows', function()
- lfs.mkdir('CamelCase')
eq('CamelCase', fix_case('camelcase'))
eq('CamelCase', fix_case('cAMELcASE'))
- lfs.rmdir('CamelCase')
end)
else
it('does nothing on Linux', function()
- lfs.mkdir('CamelCase')
eq('camelcase', fix_case('camelcase'))
eq('cAMELcASE', fix_case('cAMELcASE'))
- lfs.mkdir('CamelCase')
end)
end
end)