aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/ex_cmds/arg_spec.lua30
-rw-r--r--test/functional/ex_cmds/edit_spec.lua26
-rw-r--r--test/functional/legacy/match_conceal_spec.lua228
-rw-r--r--test/functional/legacy/undolevels_spec.lua6
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua26
5 files changed, 83 insertions, 233 deletions
diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua
new file mode 100644
index 0000000000..e66dc62491
--- /dev/null
+++ b/test/functional/ex_cmds/arg_spec.lua
@@ -0,0 +1,30 @@
+local helpers = require("test.functional.helpers")(after_each)
+local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs
+local ok = helpers.ok
+local clear = helpers.clear
+
+describe(":argument", function()
+ before_each(function()
+ clear()
+ end)
+
+ it("does not restart :terminal buffer", function()
+ execute("terminal")
+ helpers.feed([[<C-\><C-N>]])
+ execute("argadd")
+ helpers.feed([[<C-\><C-N>]])
+ local bufname_before = funcs.bufname("%")
+ local bufnr_before = funcs.bufnr("%")
+ helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity
+
+ execute("argument 1")
+ helpers.feed([[<C-\><C-N>]])
+
+ local bufname_after = funcs.bufname("%")
+ local bufnr_after = funcs.bufnr("%")
+ eq("\n["..bufname_before.."] ", helpers.eval('execute("args")'))
+ ok(funcs.line('$') > 1)
+ eq(bufname_before, bufname_after)
+ eq(bufnr_before, bufnr_after)
+ end)
+end)
diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua
new file mode 100644
index 0000000000..9e197d7466
--- /dev/null
+++ b/test/functional/ex_cmds/edit_spec.lua
@@ -0,0 +1,26 @@
+local helpers = require("test.functional.helpers")(after_each)
+local eq, execute, funcs = helpers.eq, helpers.execute, helpers.funcs
+local ok = helpers.ok
+local clear = helpers.clear
+
+describe(":edit", function()
+ before_each(function()
+ clear()
+ end)
+
+ it("without arguments does not restart :terminal buffer", function()
+ execute("terminal")
+ helpers.feed([[<C-\><C-N>]])
+ local bufname_before = funcs.bufname("%")
+ local bufnr_before = funcs.bufnr("%")
+ helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity
+
+ execute("edit")
+
+ local bufname_after = funcs.bufname("%")
+ local bufnr_after = funcs.bufnr("%")
+ ok(funcs.line('$') > 1)
+ eq(bufname_before, bufname_after)
+ eq(bufnr_before, bufnr_after)
+ end)
+end)
diff --git a/test/functional/legacy/match_conceal_spec.lua b/test/functional/legacy/match_conceal_spec.lua
deleted file mode 100644
index d95b07d695..0000000000
--- a/test/functional/legacy/match_conceal_spec.lua
+++ /dev/null
@@ -1,228 +0,0 @@
--- Test for matchadd() and conceal feature
-
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local expect = helpers.expect
-local source = helpers.source
-
-describe('match_conceal', function()
- before_each(function()
- clear()
-
- source([[
- set wildchar=^E
- 10new
- vsp
- vert resize 20
- put =\"\#\ This\ is\ a\ Test\"
- norm! mazt
-
- fu! ScreenChar(width, lines)
- let c=''
- for j in range(1,a:lines)
- for i in range(1,a:width)
- let c.=nr2char(screenchar(j, i))
- endfor
- let c.="\n"
- endfor
- return c
- endfu
-
- fu! ScreenAttr(line, pos, eval)
- let g:attr=[]
- for col in a:pos
- call add(g:attr, screenattr(a:line,col))
- endfor
- " In case all values are zero, probably the terminal
- " isn't set correctly, so catch that case
- let null = (eval(join(g:attr, '+')) == 0)
- let str=substitute(a:eval, '\d\+', 'g:attr[&]', 'g')
- if null || eval(str)
- let g:attr_test="OK: ". str
- else
- let g:attr_test="FAILED: ".str
- let g:attr_test.="\n". join(g:attr, ' ')
- let g:attr_test.="\n TERM: ". &term
- endif
- endfu
-
- fu! DoRecordScreen()
- wincmd l
- $put =printf(\"\n%s\", g:test)
- $put =g:line
- $put =g:attr_test
- wincmd p
- endfu
- ]])
- end)
-
- it('is working', function()
- source([=[
- let g:test ="Test 1: simple addmatch()"
- call matchadd('Conceal', '\%2l ')
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
-
- let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)"
- norm! 'azt
- call clearmatches()
- syntax on
- set concealcursor=n conceallevel=1
- call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
-
- let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)"
- norm! 'azt
- set conceallevel=3
- call clearmatches()
- call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 1==3 && 1==4 && 0!=5")
- call DoRecordScreen()
-
- let g:test ="Test 4: more match() (should be: #Thisisa Test)"
- norm! 'azt
- call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 0!=3 && 3==4 && 0!=5 && 3!=5")
- call DoRecordScreen()
-
- let g:test ="Test 5/1: default conceal char (should be: # This is a Test)"
- norm! 'azt
- call clearmatches()
- set conceallevel=1
- call matchadd('Conceal', '\%2l ', 10, -1, {})
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
- let g:test ="Test 5/2: default conceal char (should be: #+This+is+a+Test)"
- norm! 'azt
- set listchars=conceal:+
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
- set listchars&vi
-
- let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)"
- norm! 'azt
- call clearmatches()
- set conceallevel=1
- call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
- syn match MyConceal /\%2l / conceal containedin=ALL cchar=*
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
- let g:test ="Test 6/2: syn and match conceal (should be: #*This*is*a*Test)"
- norm! 'azt
- call clearmatches()
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
-
- let g:test ="Test 7/1: clear matches"
- norm! 'azt
- syn on
- call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
- let a=getmatches()
- call clearmatches()
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 0==2 && 0==3 && 0==4 && 0==5")
- call DoRecordScreen()
- $put =a
- call setmatches(a)
- norm! 'azt
- let g:test ="Test 7/2: reset match using setmatches()"
- norm! 'azt
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
-
- let g:test ="Test 8: using matchaddpos() (should be #Pis a Test"
- norm! 'azt
- call clearmatches()
- call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'})
- let a=getmatches()
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1!=2 && 0==2 && 0==3 && 0!=4 && 0!=5 && 4==5")
- call DoRecordScreen()
- $put =a
-
- let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)"
- norm! 'azt
- call clearmatches()
- call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"})
- redraw!
- let line=ScreenChar(winwidth(0),1)
- call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5")
- call DoRecordScreen()
- ]=])
-
- expect([=[
-
- # This is a Test
-
- Test 1: simple addmatch()
- # This is a Test
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)
- #XThisXisXaXTest
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)
- #ThisisaTest
- OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]!=g:attr[5]
-
- Test 4: more match() (should be: #Thisisa Test)
- #Thisisa Test
- OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[0]!=g:attr[3] && g:attr[3]==g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[3]!=g:attr[5]
-
- Test 5/1: default conceal char (should be: # This is a Test)
- # This is a Test
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 5/2: default conceal char (should be: #+This+is+a+Test)
- #+This+is+a+Test
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)
- #ZThisZisZaZTest
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 6/2: syn and match conceal (should be: #*This*is*a*Test)
- #*This*is*a*Test
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 7/1: clear matches
- # This is a Test
- OK: g:attr[0]==g:attr[1] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]==g:attr[4] && g:attr[0]==g:attr[5]
- {'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': 10, 'conceal': 'Z'}
-
- Test 7/2: reset match using setmatches()
- #ZThisZisZaZTest
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]
-
- Test 8: using matchaddpos() (should be #Pis a Test
- #Pis a Test
- OK: g:attr[0]!=g:attr[1] && g:attr[1]!=g:attr[2] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]!=g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[4]==g:attr[5]
- {'group': 'Conceal', 'id': 11, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'}
-
- Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)
- #ˑThisˑisˑaˑTest
- OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5]]=])
- end)
-end)
diff --git a/test/functional/legacy/undolevels_spec.lua b/test/functional/legacy/undolevels_spec.lua
index 9902b101f6..1dfc4c17ba 100644
--- a/test/functional/legacy/undolevels_spec.lua
+++ b/test/functional/legacy/undolevels_spec.lua
@@ -10,7 +10,7 @@ describe('undolevel', function()
func FillBuffer()
for i in range(1,13)
put=i
- " Set 'undolevels' to split undo.
+ " Set 'undolevels' to split undo.
exe "setg ul=" . &g:ul
endfor
endfunc
@@ -48,6 +48,10 @@ describe('undolevel', function()
call assert_equal(50, &g:undolevels)
call assert_equal(-123456, &l:undolevels)
+ " Drop created windows
+ set ul&
+ new
+ only!
endfunc
call Test_global_local_undolevels()
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 6f929f17e4..09b4eaa8d5 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -13,13 +13,19 @@ describe(':terminal', function()
clear()
screen = Screen.new(50, 4)
screen:attach({rgb=false})
+ -- shell-test.c is a fake shell that prints its arguments and exits.
nvim('set_option', 'shell', nvim_dir..'/shell-test')
nvim('set_option', 'shellcmdflag', 'EXE')
-
end)
+ -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
+ -- the {cmd} and exits immediately .
+ local function terminal_run_fake_shell_cmd(cmd)
+ execute("terminal "..(cmd and cmd or ""))
+ end
+
it('with no argument, acts like termopen()', function()
- execute('terminal')
+ terminal_run_fake_shell_cmd()
wait()
screen:expect([[
ready $ |
@@ -30,7 +36,7 @@ describe(':terminal', function()
end)
it('executes a given command through the shell', function()
- execute('terminal echo hi')
+ terminal_run_fake_shell_cmd('echo hi')
wait()
screen:expect([[
ready $ echo hi |
@@ -41,7 +47,7 @@ describe(':terminal', function()
end)
it('allows quotes and slashes', function()
- execute([[terminal echo 'hello' \ "world"]])
+ terminal_run_fake_shell_cmd([[echo 'hello' \ "world"]])
wait()
screen:expect([[
ready $ echo 'hello' \ "world" |
@@ -58,4 +64,16 @@ describe(':terminal', function()
-- Verify that BufNew actually fired (else the test is invalid).
eq('foo', eval('&shell'))
end)
+
+ it('ignores writes if the backing stream closes', function()
+ terminal_run_fake_shell_cmd()
+ helpers.feed('iiXXXXXXX')
+ wait()
+ -- Race: Though the shell exited (and streams were closed by SIGCHLD
+ -- handler), :terminal cleanup is pending on the main-loop.
+ -- This write should be ignored (not crash, #5445).
+ helpers.feed('iiYYYYYYY')
+ wait()
+ end)
+
end)