aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua9
-rw-r--r--test/functional/clipboard/clipboard_provider_spec.lua53
-rw-r--r--test/functional/eval/glob_spec.lua25
-rw-r--r--test/functional/ex_cmds/menu_spec.lua38
-rw-r--r--test/functional/ex_cmds/recover_spec.lua4
-rw-r--r--test/functional/fixtures/autoload/provider/clipboard.vim (renamed from test/functional/clipboard/autoload/provider/clipboard.vim)4
-rw-r--r--test/functional/helpers.lua25
-rw-r--r--test/functional/legacy/057_sort_spec.lua603
-rw-r--r--test/functional/legacy/080_substitute_spec.lua162
-rw-r--r--test/functional/terminal/highlight_spec.lua25
-rw-r--r--test/functional/ui/screen.lua9
-rw-r--r--test/functional/ui/screen_basic_spec.lua23
-rw-r--r--test/unit/os/fs_spec.lua63
13 files changed, 1033 insertions, 10 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index c158c26341..9e880a4f04 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -34,6 +34,15 @@ describe('vim_* functions', function()
end)
end)
+ describe('call_function', function()
+ it('works', function()
+ nvim('call_function', 'setqflist', {{{ filename = 'something', lnum = 17}}, 'r'})
+ eq(17, nvim('call_function', 'getqflist', {})[1].lnum)
+ eq(17, nvim('call_function', 'eval', {17}))
+ eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'}))
+ end)
+ end)
+
describe('strwidth', function()
it('works', function()
eq(3, nvim('strwidth', 'abc'))
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua
index 9282a66240..f6d6188d82 100644
--- a/test/functional/clipboard/clipboard_provider_spec.lua
+++ b/test/functional/clipboard/clipboard_provider_spec.lua
@@ -92,7 +92,7 @@ end)
describe('clipboard usage', function()
before_each(function()
clear()
- execute('let &rtp = "test/functional/clipboard,".&rtp')
+ execute('let &rtp = "test/functional/fixtures,".&rtp')
execute('call getreg("*")') -- force load of provider
end)
@@ -197,6 +197,17 @@ describe('clipboard usage', function()
expect('some more')
end)
+ it('pastes unnamed register if the provider fails', function()
+ insert('the text')
+ feed('yy')
+ execute("let g:cliperror = 1")
+ feed('"*p')
+ expect([[
+ the text
+ the text]])
+ end)
+
+
describe('with clipboard=unnamed', function()
-- the basic behavior of unnamed register should be the same
-- even when handled by clipboard provider
@@ -261,6 +272,16 @@ describe('clipboard usage', function()
expect("indeed star")
end)
+ it('unamed operations work even if the provider fails', function()
+ insert('the text')
+ feed('yy')
+ execute("let g:cliperror = 1")
+ feed('p')
+ expect([[
+ the text
+ the text]])
+ end)
+
end)
it('supports :put', function()
@@ -335,4 +356,34 @@ describe('clipboard usage', function()
'Howdy!',
}, 'v'}, eval("g:test_clip['*']"))
end)
+
+ it('handles middleclick correctly', function()
+ local screen = Screen.new(30, 5)
+ screen:attach()
+ insert([[
+ the source
+ a target]])
+ feed('gg"*ywwyw')
+ -- clicking depends on the exact visual layout, so expect it:
+ screen:expect([[
+ the ^source |
+ a target |
+ ~ |
+ ~ |
+ |
+ ]], nil, {{bold = true, foreground = Screen.colors.Blue}})
+
+ feed('<MiddleMouse><0,1>')
+ expect([[
+ the source
+ the a target]])
+
+ -- on error, fall back to unnamed register
+ execute("let g:cliperror = 1")
+ feed('<MiddleMouse><6,1>')
+ expect([[
+ the source
+ the a sourcetarget]])
+ end)
+
end)
diff --git a/test/functional/eval/glob_spec.lua b/test/functional/eval/glob_spec.lua
new file mode 100644
index 0000000000..136417249c
--- /dev/null
+++ b/test/functional/eval/glob_spec.lua
@@ -0,0 +1,25 @@
+local helpers = require('test.functional.helpers')
+local clear, execute, eval, eq = helpers.clear, helpers.execute, helpers.eval, helpers.eq
+
+before_each(function()
+ clear()
+ lfs.mkdir('test-glob')
+ execute('cd test-glob')
+end)
+
+after_each(function()
+ lfs.rmdir('test-glob')
+end)
+
+describe('glob()', function()
+ it("glob('.*') returns . and .. ", function()
+ eq({'.', '..'}, eval("glob('.*', 0, 1)"))
+ -- Do it again to verify scandir_next_with_dots() internal state.
+ eq({'.', '..'}, eval("glob('.*', 0, 1)"))
+ end)
+ it("glob('*') returns an empty list ", function()
+ eq({}, eval("glob('*', 0, 1)"))
+ -- Do it again to verify scandir_next_with_dots() internal state.
+ eq({}, eval("glob('*', 0, 1)"))
+ end)
+end)
diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua
new file mode 100644
index 0000000000..6af889bf9e
--- /dev/null
+++ b/test/functional/ex_cmds/menu_spec.lua
@@ -0,0 +1,38 @@
+local helpers = require('test.functional.helpers')
+local clear, execute, nvim = helpers.clear, helpers.execute, helpers.nvim
+local expect = helpers.expect
+local feed = helpers.feed
+local command = helpers.command
+
+describe(':emenu', function()
+
+ before_each(function()
+ clear()
+ execute('nnoremenu Test.Test inormal<ESC>')
+ execute('inoremenu Test.Test insert')
+ execute('vnoremenu Test.Test x')
+ end)
+
+ it('executes correct bindings in normal mode without using API', function()
+ execute('emenu Test.Test')
+ expect('normal')
+ end)
+
+ it('executes correct bindings in normal mode', function()
+ command('emenu Test.Test')
+ expect('normal')
+ end)
+
+ it('executes correct bindings in insert mode', function()
+ feed('i')
+ command('emenu Test.Test')
+ expect('insert')
+ end)
+
+ it('executes correct bindings in visual mode', function()
+ feed('iabcde<ESC>0lvll')
+ command('emenu Test.Test')
+ expect('ae')
+ end)
+
+end)
diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua
index d4c9477133..b92739e40e 100644
--- a/test/functional/ex_cmds/recover_spec.lua
+++ b/test/functional/ex_cmds/recover_spec.lua
@@ -20,11 +20,11 @@ describe(':preserve', function()
local swapdir = lfs.currentdir()..'/testdir_recover_spec'
before_each(function()
clear()
- os.remove(swapdir)
+ helpers.rmdir(swapdir)
lfs.mkdir(swapdir)
end)
after_each(function()
- os.remove(swapdir)
+ helpers.rmdir(swapdir)
end)
it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()
diff --git a/test/functional/clipboard/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim
index d88b68464e..a28484169a 100644
--- a/test/functional/clipboard/autoload/provider/clipboard.vim
+++ b/test/functional/fixtures/autoload/provider/clipboard.vim
@@ -3,8 +3,12 @@ let g:test_clip = { '+': [''], '*': [''], }
let s:methods = {}
let g:cliplossy = 0
+let g:cliperror = 0
function! s:methods.get(reg)
+ if g:cliperror
+ return 0
+ end
if g:cliplossy
" behave like pure text clipboard
return g:test_clip[a:reg][0]
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 33d04616a0..d5c22c6f1c 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -290,6 +290,28 @@ local function expect(contents)
return eq(dedent(contents), curbuf_contents())
end
+local function rmdir(path)
+ if lfs.attributes(path, 'mode') ~= 'directory' then
+ return nil
+ end
+ for file in lfs.dir(path) do
+ if file == '.' or file == '..' then
+ goto continue
+ end
+ ret, err = os.remove(path..'/'..file)
+ if not ret then
+ error('os.remove: '..err)
+ return nil
+ end
+ ::continue::
+ end
+ ret, err = os.remove(path)
+ if not ret then
+ error('os.remove: '..err)
+ end
+ return ret
+end
+
return {
clear = clear,
spawn = spawn,
@@ -321,5 +343,6 @@ return {
curbuf_contents = curbuf_contents,
wait = wait,
set_session = set_session,
- write_file = write_file
+ write_file = write_file,
+ rmdir = rmdir
}
diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua
new file mode 100644
index 0000000000..585b391198
--- /dev/null
+++ b/test/functional/legacy/057_sort_spec.lua
@@ -0,0 +1,603 @@
+-- Tests for :sort command.
+
+local helpers = require('test.functional.helpers')
+local insert, execute, clear, expect, eq, eval, source = helpers.insert,
+ helpers.execute, helpers.clear, helpers.expect, helpers.eq, helpers.eval,
+ helpers.source
+
+describe(':sort', function()
+ local text = [[
+ abc
+ ab
+ a
+ a321
+ a123
+ a122
+ b321
+ b123
+ c123d
+ 123b
+ c321d
+ b322b
+ b321
+ b321b
+ ]]
+ before_each(clear)
+
+ it('alphabetical', function()
+ insert(text)
+ execute('sort')
+ expect([[
+
+ 123b
+ a
+ a122
+ a123
+ a321
+ ab
+ abc
+ b123
+ b321
+ b321
+ b321b
+ b322b
+ c123d
+ c321d]])
+ end)
+
+ it('numerical', function()
+ insert([[
+ abc
+ ab
+ a321
+ a123
+ a122
+ a
+ x-22
+ b321
+ b123
+ c123d
+ -24
+ 123b
+ c321d
+ 0
+ b322b
+ b321
+ b321b
+ ]])
+ execute('sort n')
+ expect([[
+ abc
+ ab
+ a
+
+ -24
+ x-22
+ 0
+ a122
+ a123
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b321
+ b321b
+ b322b]])
+ end)
+
+ it('hexadecimal', function()
+ insert(text)
+ execute('sort x')
+ expect([[
+
+ a
+ ab
+ abc
+ 123b
+ a122
+ a123
+ a321
+ b123
+ b321
+ b321
+ b321b
+ b322b
+ c123d
+ c321d]])
+ end)
+
+ it('alphabetical, unique', function()
+ insert(text)
+ execute('sort u')
+ expect([[
+
+ 123b
+ a
+ a122
+ a123
+ a321
+ ab
+ abc
+ b123
+ b321
+ b321b
+ b322b
+ c123d
+ c321d]])
+ end)
+
+ it('alphabetical, reverse', function()
+ insert(text)
+ execute('sort!')
+ expect([[
+ c321d
+ c123d
+ b322b
+ b321b
+ b321
+ b321
+ b123
+ abc
+ ab
+ a321
+ a123
+ a122
+ a
+ 123b
+ ]])
+ end)
+
+ it('numerical, reverse', function()
+ insert(text)
+ execute('sort! n')
+ expect([[
+ b322b
+ b321b
+ b321
+ c321d
+ b321
+ a321
+ 123b
+ c123d
+ b123
+ a123
+ a122
+
+ a
+ ab
+ abc]])
+ end)
+
+ it('unique, reverse', function()
+ insert(text)
+ execute('sort! u')
+ expect([[
+ c321d
+ c123d
+ b322b
+ b321b
+ b321
+ b123
+ abc
+ ab
+ a321
+ a123
+ a122
+ a
+ 123b
+ ]])
+ end)
+
+ it('octal', function()
+ insert(text)
+ execute('sort o')
+ expect([[
+ abc
+ ab
+ a
+
+ a122
+ a123
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b321
+ b321b
+ b322b]])
+ end)
+
+ it('reverse, hexadecimal', function()
+ insert(text)
+ execute('sort! x')
+ expect([[
+ c321d
+ c123d
+ b322b
+ b321b
+ b321
+ b321
+ b123
+ a321
+ a123
+ a122
+ 123b
+ abc
+ ab
+ a
+ ]])
+ end)
+
+ it('alphabetical, skip first character', function()
+ insert(text)
+ execute('sort/./')
+ expect([[
+ a
+
+ a122
+ a123
+ b123
+ 123b
+ c123d
+ a321
+ b321
+ b321
+ b321b
+ c321d
+ b322b
+ ab
+ abc]])
+ end)
+
+ it('alphabetical, skip first 2 characters', function()
+ insert(text)
+ execute('sort/../')
+ expect([[
+ ab
+ a
+
+ a321
+ b321
+ b321
+ b321b
+ c321d
+ a122
+ b322b
+ a123
+ b123
+ 123b
+ c123d
+ abc]])
+ end)
+
+ it('alphabetical, unique, skip first 2 characters', function()
+ insert(text)
+ execute('sort/../u')
+ expect([[
+ ab
+ a
+
+ a321
+ b321
+ b321b
+ c321d
+ a122
+ b322b
+ a123
+ b123
+ 123b
+ c123d
+ abc]])
+ end)
+
+ it('numerical, skip first character', function()
+ insert(text)
+ execute('sort/./n')
+ expect([[
+ abc
+ ab
+ a
+
+ a122
+ a123
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b321
+ b321b
+ b322b]])
+ end)
+
+ it('alphabetical, sort on first character', function()
+ insert(text)
+ execute('sort/./r')
+ expect([[
+
+ 123b
+ abc
+ ab
+ a
+ a321
+ a123
+ a122
+ b321
+ b123
+ b322b
+ b321
+ b321b
+ c123d
+ c321d]])
+ end)
+
+ it('alphabetical, sort on first 2 characters', function()
+ insert(text)
+ execute('sort/../r')
+ expect([[
+ a
+
+ 123b
+ a123
+ a122
+ a321
+ abc
+ ab
+ b123
+ b321
+ b322b
+ b321
+ b321b
+ c123d
+ c321d]])
+ end)
+
+ it('numerical, sort on first character', function()
+ insert(text)
+ execute('sort/./rn')
+ expect([[
+ abc
+ ab
+ a
+ a321
+ a123
+ a122
+ b321
+ b123
+ c123d
+ 123b
+ c321d
+ b322b
+ b321
+ b321b
+ ]])
+ end)
+
+ it('alphabetical, skip past first digit', function()
+ insert(text)
+ execute([[sort/\d/]])
+ expect([[
+ abc
+ ab
+ a
+
+ a321
+ b321
+ b321
+ b321b
+ c321d
+ a122
+ b322b
+ a123
+ b123
+ 123b
+ c123d]])
+ end)
+
+ it('alphabetical, sort on first digit', function()
+ insert(text)
+ execute([[sort/\d/r]])
+ expect([[
+ abc
+ ab
+ a
+
+ a123
+ a122
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b322b
+ b321
+ b321b]])
+ end)
+
+ it('numerical, skip past first digit', function()
+ insert(text)
+ execute([[sort/\d/n]])
+ expect([[
+ abc
+ ab
+ a
+
+ a321
+ b321
+ c321d
+ b321
+ b321b
+ a122
+ b322b
+ a123
+ b123
+ c123d
+ 123b]])
+ end)
+
+ it('numerical, sort on first digit', function()
+ insert(text)
+ execute([[sort/\d/rn]])
+ expect([[
+ abc
+ ab
+ a
+
+ a123
+ a122
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b322b
+ b321
+ b321b]])
+ end)
+
+ it('alphabetical, skip past first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/]])
+ expect([[
+ abc
+ ab
+ a
+
+ a321
+ b321
+ b321
+ b321b
+ c321d
+ a122
+ b322b
+ a123
+ b123
+ 123b
+ c123d]])
+ end)
+
+ it('numerical, skip past first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/n]])
+ expect([[
+ abc
+ ab
+ a
+
+ a321
+ b321
+ c321d
+ b321
+ b321b
+ a122
+ b322b
+ a123
+ b123
+ c123d
+ 123b]])
+ end)
+
+ it('hexadecimal, skip past first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/x]])
+ expect([[
+ abc
+ ab
+ a
+
+ a321
+ b321
+ b321
+ a122
+ a123
+ b123
+ b321b
+ c321d
+ b322b
+ 123b
+ c123d]])
+ end)
+
+ it('alpha, on first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/r]])
+ expect([[
+ abc
+ ab
+ a
+
+ a123
+ a122
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b322b
+ b321
+ b321b]])
+ end)
+
+ it('numeric, on first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/rn]])
+ expect([[
+ abc
+ ab
+ a
+
+ a123
+ a122
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b322b
+ b321
+ b321b]])
+ end)
+
+ it('hexadecimal, on first 2 digits', function()
+ insert(text)
+ execute([[sort/\d\d/rx]])
+ expect([[
+ abc
+ ab
+ a
+
+ a123
+ a122
+ b123
+ c123d
+ 123b
+ a321
+ b321
+ c321d
+ b322b
+ b321
+ b321b]])
+ end)
+
+ it('fails with wrong arguments', function()
+ insert(text)
+ -- This should fail with "E474: Invalid argument".
+ source([[
+ try
+ sort no
+ catch
+ let tmpvar = v:exception
+ endtry]])
+ eq('Vim(sort):E474: Invalid argument', eval('tmpvar'))
+ expect(text)
+ end)
+end)
diff --git a/test/functional/legacy/080_substitute_spec.lua b/test/functional/legacy/080_substitute_spec.lua
new file mode 100644
index 0000000000..89ef7a713c
--- /dev/null
+++ b/test/functional/legacy/080_substitute_spec.lua
@@ -0,0 +1,162 @@
+-- Test for *sub-replace-special* and *sub-replace-expression* on substitue().
+-- Test for submatch() on substitue().
+-- Test for *:s%* on :substitute.
+
+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
+local eq, eval = helpers.eq, helpers.eval
+
+describe('substitue()', function()
+ before_each(clear)
+
+ -- The original test contained several TEST_X lines to delimit different
+ -- parts. These where used to split the test into different it() blocks.
+ -- The TEST_X strings are repeated in the description of the blocks to make
+ -- it easier to incorporate upstream changes.
+
+ local function test_1_and_2()
+ eq('AA', eval("substitute('A', 'A', '&&', '')"))
+ eq('&', eval([[substitute('B', 'B', '\&', '')]]))
+ eq('C123456789987654321', eval([[substitute('C123456789', ]] ..
+ [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
+ [['\0\9\8\7\6\5\4\3\2\1', '')]]))
+ eq('d', eval("substitute('D', 'D', 'd', '')"))
+ eq('~', eval("substitute('E', 'E', '~', '')"))
+ eq('~', eval([[substitute('F', 'F', '\~', '')]]))
+ eq('Gg', eval([[substitute('G', 'G', '\ugg', '')]]))
+ eq('Hh', eval([[substitute('H', 'H', '\Uh\Eh', '')]]))
+ eq('iI', eval([[substitute('I', 'I', '\lII', '')]]))
+ eq('jJ', eval([[substitute('J', 'J', '\LJ\EJ', '')]]))
+ eq('Kk', eval([[substitute('K', 'K', '\Uk\ek', '')]]))
+ eq('l\rl', eval("substitute('lLl', 'L', '\r', '')"))
+ eq('m\rm', eval([[substitute('mMm', 'M', '\r', '')]]))
+ eq('n\rn', eval("substitute('nNn', 'N', '\\\r', '')"))
+ eq('o\no', eval([[substitute('oOo', 'O', '\n', '')]]))
+ eq('p\bp', eval([[substitute('pPp', 'P', '\b', '')]]))
+ eq('q\tq', eval([[substitute('qQq', 'Q', '\t', '')]]))
+ eq('r\\r', eval([[substitute('rRr', 'R', '\\', '')]]))
+ eq('scs', eval([[substitute('sSs', 'S', '\c', '')]]))
+ eq('t\rt', eval([[substitute('tTt', 'T', "\r", '')]]))
+ eq('u\nu', eval([[substitute('uUu', 'U', "\n", '')]]))
+ eq('v\bv', eval([[substitute('vVv', 'V', "\b", '')]]))
+ eq('w\\w', eval([[substitute('wWw', 'W', "\\", '')]]))
+ eq('XxxX', eval([[substitute('X', 'X', '\L\uxXx\l\EX', '')]]))
+ eq('yYYy', eval([[substitute('Y', 'Y', '\U\lYyY\u\Ey', '')]]))
+ end
+
+ it('with "set magic" (TEST_1)', function()
+ execute('set magic')
+ test_1_and_2()
+ end)
+
+ it('with "set nomagic" (TEST_2)', function()
+ execute('set nomagic')
+ test_1_and_2()
+ end)
+
+ it('with sub-replace-expression (TEST_3)', function()
+ execute('set magic&')
+ eq('a\\a', eval([[substitute('aAa', 'A', '\="\\"', '')]]))
+ eq('b\\\\b', eval([[substitute('bBb', 'B', '\="\\\\"', '')]]))
+ eq('c\rc', eval([[substitute('cCc', 'C', '\="]]..'\r'..[["', '')]]))
+ eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]]..'\r'..[["', '')]]))
+ eq('e\\\\\re',
+ eval([[substitute('eEe', 'E', '\="\\\\]]..'\r'..[["', '')]]))
+ eq('f\\rf', eval([[substitute('fFf', 'F', '\="\\r"', '')]]))
+ eq('j\\nj', eval([[substitute('jJj', 'J', '\="\\n"', '')]]))
+ eq('k\rk', eval([[substitute('kKk', 'K', '\="\r"', '')]]))
+ eq('l\nl', eval([[substitute('lLl', 'L', '\="\n"', '')]]))
+ end)
+
+ it('with submatch() (TEST_4)', function()
+ execute('set magic&')
+ eq('a\\a', eval([[substitute('aAa', 'A', ]] ..
+ [['\=substitute(submatch(0), ".", "\\", "")', '')]]))
+ eq('b\\b', eval([[substitute('bBb', 'B', ]] ..
+ [['\=substitute(submatch(0), ".", "\\\\", "")', '')]]))
+ eq('c\rc', eval([[substitute('cCc', 'C', ]] ..
+ [['\=substitute(submatch(0), ".", "]]..'\r'..[[", "")', '')]]))
+ eq('d\rd', eval([[substitute('dDd', 'D', ]] ..
+ [['\=substitute(submatch(0), ".", "\\]]..'\r'..[[", "")', '')]]))
+ eq('e\\\re', eval([[substitute('eEe', 'E', ]] ..
+ [['\=substitute(submatch(0), ".", "\\\\]]..'\r'..[[", "")', '')]]))
+ eq('f\rf', eval([[substitute('fFf', 'F', ]] ..
+ [['\=substitute(submatch(0), ".", "\\r", "")', '')]]))
+ eq('j\nj', eval([[substitute('jJj', 'J', ]] ..
+ [['\=substitute(submatch(0), ".", "\\n", "")', '')]]))
+ eq('k\rk', eval([[substitute('kKk', 'K', ]] ..
+ [['\=substitute(submatch(0), ".", "\r", "")', '')]]))
+ eq('l\nl', eval([[substitute('lLl', 'L', ]] ..
+ [['\=substitute(submatch(0), ".", "\n", "")', '')]]))
+ end)
+
+ it('with submatch() (TEST_5)', function()
+ execute('set magic&')
+ eq('A123456789987654321', eval([[substitute('A123456789', ]] ..
+ [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
+ [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]] ..
+ [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]] ..
+ [[submatch(2) . submatch(1)', '')]]))
+ eq("[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " ..
+ "['2'], ['1']]", eval([[substitute('A123456789', ]] ..
+ [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
+ [['\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), ]] ..
+ [[submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), ]] ..
+ [[submatch(3, 1), submatch(2, 1), submatch(1, 1)])', '')]]))
+ end)
+
+ -- TEST_6 was about the 'cpoptions' flag / which was removed in pull request
+ -- #2943.
+
+ it('with submatch or \\ze (TEST_7)', function()
+ execute('set magic&')
+ eq('A\rA', eval("substitute('A\rA', 'A.', '\\=submatch(0)', '')"))
+ eq('B\nB', eval([[substitute("B\nB", 'B.', '\=submatch(0)', '')]]))
+ eq("['B\n']B",
+ eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]]))
+ eq('-abab', eval([[substitute('-bb', '\zeb', 'a', 'g')]]))
+ eq('c-cbcbc', eval([[substitute('-bb', '\ze', 'c', 'g')]]))
+ end)
+
+ it('with \\zs and \\ze (TEST_10)', function()
+ execute('set magic&')
+ eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]]))
+ eq('aaa', eval([[substitute('123', '\zs.', 'a', 'g')]]))
+ eq('1a2a3a', eval([[substitute('123', '.\zs', 'a', 'g')]]))
+ eq('a1a2a3a', eval([[substitute('123', '\ze', 'a', 'g')]]))
+ eq('a1a2a3', eval([[substitute('123', '\ze.', 'a', 'g')]]))
+ eq('aaa', eval([[substitute('123', '.\ze', 'a', 'g')]]))
+ eq('aa2a3a', eval([[substitute('123', '1\|\ze', 'a', 'g')]]))
+ eq('1aaa', eval([[substitute('123', '1\zs\|[23]', 'a', 'g')]]))
+ end)
+end)
+
+describe(':substitue', function()
+ before_each(clear)
+
+ it('with \\ze and \\zs and confirmation dialog (TEST_8)', function()
+ insert([[
+ ,,X
+ ,,Y
+ ,,Z]])
+ execute('set magic&')
+ execute([[1s/\(^\|,\)\ze\(,\|X\)/\1N/g]])
+ execute([[2s/\(^\|,\)\ze\(,\|Y\)/\1N/gc]])
+ feed('a') -- For the dialog of the previous :s command.
+ execute([[3s/\(^\|,\)\ze\(,\|Z\)/\1N/gc]])
+ feed('yy') -- For the dialog of the previous :s command.
+ expect([[
+ N,,NX
+ N,,NY
+ N,,NZ]])
+ end)
+
+ it('with confirmation dialog (TEST_9)', function()
+ insert('xxx')
+ execute('set magic&')
+ execute('s/x/X/gc')
+ feed('yyq') -- For the dialog of the previous :s command.
+ expect('XXx')
+ end)
+end)
diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua
index b72527e7b6..1a96cb4dba 100644
--- a/test/functional/terminal/highlight_spec.lua
+++ b/test/functional/terminal/highlight_spec.lua
@@ -3,6 +3,7 @@ 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 nvim_dir, execute = helpers.nvim_dir, helpers.execute
+local eq, eval = helpers.eq, helpers.eval
describe('terminal window highlighting', function()
@@ -161,3 +162,27 @@ describe('terminal window highlighting with custom palette', function()
]])
end)
end)
+
+describe('synIDattr()', function()
+ local screen
+
+ before_each(function()
+ clear()
+ screen = Screen.new(50, 7)
+ execute('highlight Normal ctermfg=1 guifg=#ff0000')
+ end)
+
+ after_each(function()
+ screen:detach()
+ end)
+
+ it('returns RGB number if GUI', function()
+ screen:attach(true)
+ eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
+ end)
+
+ it('returns color number if non-GUI', function()
+ screen:attach(false)
+ eq('1', eval('synIDattr(hlID("Normal"), "fg")'))
+ end)
+end)
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 60198bb008..1d616ed853 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -340,12 +340,9 @@ function Screen:_handle_mouse_off()
self._mouse_enabled = false
end
-function Screen:_handle_insert_mode()
- self._mode = 'insert'
-end
-
-function Screen:_handle_normal_mode()
- self._mode = 'normal'
+function Screen:_handle_mode_change(mode)
+ assert(mode == 'insert' or mode == 'replace' or mode == 'normal')
+ self._mode = mode
end
function Screen:_handle_set_scroll_region(top, bot, left, right)
diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua
index 472c211ab7..421c167300 100644
--- a/test/functional/ui/screen_basic_spec.lua
+++ b/test/functional/ui/screen_basic_spec.lua
@@ -63,6 +63,29 @@ describe('Screen', function()
end
end)
end)
+
+ it('has correct default title with unnamed file', function()
+ local expected = '[No Name] - NVIM'
+ execute('set title')
+ screen:wait(function()
+ local actual = screen.title
+ if actual ~= expected then
+ return 'Expected title to be "'..expected..'" but was "'..actual..'"'
+ end
+ end)
+ end)
+
+ it('has correct default title with named file', function()
+ local expected = 'myfile (/mydir) - NVIM'
+ execute('set title')
+ execute('file /mydir/myfile')
+ screen:wait(function()
+ local actual = screen.title
+ if actual ~= expected then
+ return 'Expected title to be "'..expected..'" but was "'..actual..'"'
+ end
+ end)
+ end)
end)
describe(':set icon', function()
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 2ffffb907f..20aca9109e 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -486,6 +486,16 @@ describe('fs function', function()
return fs.os_rmdir(to_cstr(path))
end
+ local function os_mkdir_recurse(path, mode)
+ local failed_str = ffi.new('char *[1]', {nil})
+ local ret = fs.os_mkdir_recurse(path, mode, failed_str)
+ local str = failed_str[0]
+ if str ~= nil then
+ str = ffi.string(str)
+ end
+ return ret, str
+ end
+
describe('os_mkdir', function()
it('returns non-zero when given an already existing directory', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
@@ -501,6 +511,59 @@ describe('fs function', function()
end)
end)
+ describe('os_mkdir_recurse', function()
+ it('returns zero when given an already existing directory', function()
+ local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
+ local ret, failed_str = os_mkdir_recurse('unit-test-directory', mode)
+ eq(0, ret)
+ eq(nil, failed_str)
+ end)
+
+ it('fails to create a directory where there is a file', function()
+ local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
+ local ret, failed_str = os_mkdir_recurse(
+ 'unit-test-directory/test.file', mode)
+ neq(0, ret)
+ eq('unit-test-directory/test.file', failed_str)
+ end)
+
+ it('fails to create a directory where there is a file in path', function()
+ local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
+ local ret, failed_str = os_mkdir_recurse(
+ 'unit-test-directory/test.file/test', mode)
+ neq(0, ret)
+ eq('unit-test-directory/test.file', failed_str)
+ end)
+
+ it('succeeds to create a directory', function()
+ local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
+ local ret, failed_str = os_mkdir_recurse(
+ 'unit-test-directory/new-dir-recurse', mode)
+ eq(0, ret)
+ eq(nil, failed_str)
+ eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
+ lfs.rmdir('unit-test-directory/new-dir-recurse')
+ eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
+ end)
+
+ it('succeeds to create a directory tree', function()
+ local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
+ local ret, failed_str = os_mkdir_recurse(
+ 'unit-test-directory/new-dir-recurse/1/2/3', mode)
+ eq(0, ret)
+ eq(nil, failed_str)
+ eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
+ eq(true, os_isdir('unit-test-directory/new-dir-recurse/1'))
+ eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2'))
+ eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2/3'))
+ lfs.rmdir('unit-test-directory/new-dir-recurse/1/2/3')
+ lfs.rmdir('unit-test-directory/new-dir-recurse/1/2')
+ lfs.rmdir('unit-test-directory/new-dir-recurse/1')
+ lfs.rmdir('unit-test-directory/new-dir-recurse')
+ eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
+ end)
+ end)
+
describe('os_rmdir', function()
it('returns non_zero when given a non-existing directory', function()
neq(0, (os_rmdir('non-existing-directory')))