diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/legacy/019_smarttab_expandtab_spec.lua | 56 | ||||
-rw-r--r-- | test/functional/legacy/063_match_and_matchadd_spec.lua | 141 | ||||
-rw-r--r-- | test/functional/legacy/089_number_relnumber_findfile_spec.lua | 116 | ||||
-rw-r--r-- | test/functional/shell/viml_system_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 15 | ||||
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/searchhl_spec.lua | 241 |
7 files changed, 565 insertions, 10 deletions
diff --git a/test/functional/legacy/019_smarttab_expandtab_spec.lua b/test/functional/legacy/019_smarttab_expandtab_spec.lua new file mode 100644 index 0000000000..a33bd0c3ae --- /dev/null +++ b/test/functional/legacy/019_smarttab_expandtab_spec.lua @@ -0,0 +1,56 @@ +-- Tests for "r<Tab>" with 'smarttab' and 'expandtab' set/not set. +-- Also test that dv_ works correctly + +local helpers = require('test.functional.helpers') +local feed, insert = helpers.feed, helpers.insert +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe([[performing "r<Tab>" with 'smarttab' and 'expandtab' set/not set, and "dv_"]], function() + setup(clear) + + it('is working', function() + insert([[ + start text + some test text + test text + other test text + a cde + f ghi + test text + Second line beginning with whitespace]]) + + execute('set smarttab expandtab ts=8 sw=4') + -- Make sure that backspace works, no matter what termcap is used. + execute('set t_kD=x7f t_kb=x08') + + execute('/some') + feed('r ') + execute('set noexpandtab') + execute('/other') + feed('r <cr>') + -- Test replacing with Tabs and then backspacing to undo it. + feed('0wR <bs><bs><bs><esc><cr>') + -- Test replacing with Tabs. + feed('0wR <esc><cr>') + -- Test that copyindent works with expandtab set. + execute('set expandtab smartindent copyindent ts=8 sw=8 sts=8') + feed('o{<cr>x<esc>') + execute('set nosol') + execute('/Second line/') + -- Test "dv_" + feed('fwdv_') + + -- Assert buffer contents. + expect([[ + start text + ome test text + test text + ther test text + a cde + hi + test text + { + x + with whitespace]]) + end) +end) diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua new file mode 100644 index 0000000000..d819db7812 --- /dev/null +++ b/test/functional/legacy/063_match_and_matchadd_spec.lua @@ -0,0 +1,141 @@ +-- Tests for adjusting window and contents + +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local eval, clear, execute, expect = helpers.eval, helpers.clear, helpers.execute +local expect, eq, neq = helpers.expect, helpers.eq, helpers.neq +local command = helpers.command + +describe('063: Test for ":match", "matchadd()" and related functions', function() + setup(clear) + + it('is working', function() + local screen = Screen.new(40, 5) + screen:attach() + + -- Check that "matcharg()" returns the correct group and pattern if a match + -- is defined. + execute("highlight MyGroup1 term=bold ctermbg=red guibg=red") + execute("highlight MyGroup2 term=italic ctermbg=green guibg=green") + execute("highlight MyGroup3 term=underline ctermbg=blue guibg=blue") + execute("match MyGroup1 /TODO/") + execute("2match MyGroup2 /FIXME/") + execute("3match MyGroup3 /XXX/") + eq({'MyGroup1', 'TODO'}, eval('matcharg(1)')) + eq({'MyGroup2', 'FIXME'}, eval('matcharg(2)')) + eq({'MyGroup3', 'XXX'}, eval('matcharg(3)')) + + -- Check that "matcharg()" returns an empty list if the argument is not 1, + -- 2 or 3 (only 0 and 4 are tested). + eq({}, eval('matcharg(0)')) + eq({}, eval('matcharg(4)')) + + -- Check that "matcharg()" returns ['', ''] if a match is not defined. + execute("match") + execute("2match") + execute("3match") + eq({'', ''}, eval('matcharg(1)')) + eq({'', ''}, eval('matcharg(2)')) + eq({'', ''}, eval('matcharg(3)')) + + -- Check that "matchadd()" and "getmatches()" agree on added matches and + -- that default values apply. + execute("let m1 = matchadd('MyGroup1', 'TODO')") + execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 4}, + {group = 'MyGroup2', pattern = 'FIXME', priority = 42, id = 5}, + {group = 'MyGroup3', pattern = 'XXX', priority = 60, id = 17}}, + eval('getmatches()')) + + -- Check that "matchdelete()" deletes the matches defined in the previous + -- test correctly. + execute("call matchdelete(m1)") + execute("call matchdelete(m2)") + execute("call matchdelete(m3)") + eq({}, eval('getmatches()')) + + --- Check that "matchdelete()" returns 0 if successful and otherwise -1. + execute("let m = matchadd('MyGroup1', 'TODO')") + eq(0, eval('matchdelete(m)')) + + -- matchdelete throws error and returns -1 on failure + neq(true, pcall(function() eval('matchdelete(42)') end)) + execute("let r2 = matchdelete(42)") + eq(-1, eval('r2')) + + -- Check that "clearmatches()" clears all matches defined by ":match" and + -- "matchadd()". + execute("let m1 = matchadd('MyGroup1', 'TODO')") + execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + execute("match MyGroup1 /COFFEE/") + execute("2match MyGroup2 /HUMPPA/") + execute("3match MyGroup3 /VIM/") + execute("call clearmatches()") + eq({}, eval('getmatches()')) + + -- Check that "setmatches()" restores a list of matches saved by + -- "getmatches()" without changes. (Matches with equal priority must also + -- remain in the same order.) + execute("let m1 = matchadd('MyGroup1', 'TODO')") + execute("let m2 = matchadd('MyGroup2', 'FIXME', 42)") + execute("let m3 = matchadd('MyGroup3', 'XXX', 60, 17)") + execute("match MyGroup1 /COFFEE/") + execute("2match MyGroup2 /HUMPPA/") + execute("3match MyGroup3 /VIM/") + execute("let ml = getmatches()") + ml = eval("ml") + execute("call clearmatches()") + execute("call setmatches(ml)") + eq(ml, eval('getmatches()')) + execute("call clearmatches()") + + -- Check that "setmatches()" will not add two matches with the same ID. The + -- expected behaviour (for now) is to add the first match but not the + -- second and to return 0 (even though it is a matter of debate whether + -- this can be considered successful behaviour). + execute("let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])") + feed("<cr>") + eq(0, eval("r1")) + eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 1}}, eval('getmatches()')) + + -- Check that "setmatches()" returns 0 if successful and otherwise -1. + -- (A range of valid and invalid input values are tried out to generate the + -- return values.) + eq(0,eval("setmatches([])")) + eq(0,eval("setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])")) + execute("call clearmatches()") + execute("let rf1 = setmatches(0)") + eq(-1, eval('rf1')) + execute("let rf2 = setmatches([0])") + eq(-1, eval('rf2')) + execute("let rf3 = setmatches([{'wrong key': 'wrong value'}])") + feed("<cr>") + eq(-1, eval('rf3')) + + -- Check that "matchaddpos()" positions matches correctly + insert('abcdefghijklmnopq') + execute("call matchaddpos('MyGroup1', [[1, 5], [1, 8, 3]], 10, 3)") + screen:expect([[ + abcd{1:e}fg{1:hij}klmnop^q | + ~ | + ~ | + ~ | + | + ]], {[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) + + execute("call clearmatches()") + execute("call setline(1, 'abcdΣabcdef')") + execute("call matchaddpos('MyGroup1', [[1, 4, 2], [1, 9, 2]])") + screen:expect([[ + abc{1:dΣ}ab{1:cd}e^f | + ~ | + ~ | + ~ | + | + ]],{[1] = {background = Screen.colors.Red}}, {{bold = true, foreground = Screen.colors.Blue}}) + end) +end) + diff --git a/test/functional/legacy/089_number_relnumber_findfile_spec.lua b/test/functional/legacy/089_number_relnumber_findfile_spec.lua new file mode 100644 index 0000000000..1f8e49cc81 --- /dev/null +++ b/test/functional/legacy/089_number_relnumber_findfile_spec.lua @@ -0,0 +1,116 @@ +-- - Some tests for setting 'number' and 'relativenumber' +-- This is not all that useful now that the options are no longer reset when +-- setting the other. + +local helpers = require('test.functional.helpers') +local feed = helpers.feed +local clear, execute, expect, source = helpers.clear, helpers.execute, helpers.expect, helpers.source + +describe("setting 'number' and 'relativenumber'", function() + setup(clear) + + it('is working', function() + source([[ + set hidden nu rnu + redir @a | set nu? | set rnu? | redir END + e! xx + redir @b | set nu? | set rnu? | redir END + e! # + $put ='results:' + $put a + $put b + + set nonu nornu + setglobal nu + setlocal rnu + redir @c | setglobal nu? | redir END + set nonu nornu + setglobal rnu + setlocal nu + redir @d | setglobal rnu? | redir END + $put =':setlocal must NOT reset the other global value' + $put c + $put d + + set nonu nornu + setglobal nu + setglobal rnu + redir @e | setglobal nu? | redir END + set nonu nornu + setglobal rnu + setglobal nu + redir @f | setglobal rnu? | redir END + $put =':setglobal MUST reset the other global value' + $put e + $put f + + set nonu nornu + set nu + set rnu + redir @g | setglobal nu? | redir END + set nonu nornu + set rnu + set nu + redir @h | setglobal rnu? | redir END + $put =':set MUST reset the other global value' + $put g + $put h + ]]) + + -- Remove empty line + feed('ggdd') + + -- Assert buffer contents. + expect([[ + results: + + number + relativenumber + + number + relativenumber + :setlocal must NOT reset the other global value + + number + + relativenumber + :setglobal MUST reset the other global value + + number + + relativenumber + :set MUST reset the other global value + + number + + relativenumber]]) + end) +end) + +-- - Some tests for findfile() function +describe('findfile', function() + setup(clear) + + it('is working', function() + -- Assume test is being run from project root + source([[ + $put ='Testing findfile' + $put ='' + set ssl + $put =findfile('vim.c','src/nvim/ap*') + cd src/nvim + $put =findfile('vim.c','ap*') + $put =findfile('vim.c','api') + ]]) + + -- Remove empty line + feed('ggdd') + + expect([[ + Testing findfile + + src/nvim/api/vim.c + api/vim.c + api/vim.c]]) + end) +end) diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua index 2742e23e00..c9ae92048c 100644 --- a/test/functional/shell/viml_system_spec.lua +++ b/test/functional/shell/viml_system_spec.lua @@ -93,7 +93,7 @@ describe('system()', function() ~ | ~ | ~ | - ^:call system("yes") | + :call system("yes") | ]]) feed('<c-c>') screen:expect([[ @@ -259,7 +259,7 @@ describe('systemlist()', function() ~ | ~ | ~ | - ^:call systemlist("yes | xargs") | + :call systemlist("yes | xargs") | ]]) feed('<c-c>') screen:expect([[ diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 585037466e..f79d634536 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -164,8 +164,9 @@ function Screen.new(width, height) _mouse_enabled = true, _attrs = {}, _cursor = { - enabled = true, row = 1, col = 1 - } + row = 1, col = 1 + }, + _busy = false }, Screen) self:_handle_resize(width, height) return self @@ -282,12 +283,12 @@ function Screen:_handle_cursor_goto(row, col) self._cursor.col = col + 1 end -function Screen:_handle_cursor_on() - self._cursor.enabled = true +function Screen:_handle_busy_start() + self._busy = true end -function Screen:_handle_cursor_off() - self._cursor.enabled = false +function Screen:_handle_busy_stop() + self._busy = false end function Screen:_handle_mouse_on() @@ -416,7 +417,7 @@ function Screen:_row_repr(row, attr_ids, attr_ignore) table.insert(rv, '{' .. attr_id .. ':') current_attr_id = attr_id end - if self._rows[self._cursor.row] == row and self._cursor.col == i then + if not self._busy and self._rows[self._cursor.row] == row and self._cursor.col == i then table.insert(rv, '^') end table.insert(rv, row[i].text) diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 366a0af453..034e9a05d7 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -10,7 +10,7 @@ describe('Screen', function() clear() screen = Screen.new() screen:attach() - screen:set_default_attr_ignore( {{}, {bold=true, foreground=255}} ) + screen:set_default_attr_ignore( {{bold=true, foreground=255}} ) end) after_each(function() diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua new file mode 100644 index 0000000000..6986abdd65 --- /dev/null +++ b/test/functional/ui/searchhl_spec.lua @@ -0,0 +1,241 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local clear, feed, nvim, insert = helpers.clear, helpers.feed, helpers.nvim, helpers.insert +local execute, request, eq = helpers.execute, helpers.request, helpers.eq + +describe('search highlighting', function() + local screen + local colors = Screen.colors + local hl_colors = { + NonText = colors.Blue, + Search = colors.Yellow, + Message = colors.Red, + } + + before_each(function() + clear() + screen = Screen.new(40, 7) + screen:attach() + --ignore highligting of ~-lines + screen:set_default_attr_ids( { + [1] = {background = hl_colors.Search}, + [2] = {reverse = true}, + [3] = {foreground = hl_colors.Message}, + }) + screen:set_default_attr_ignore( {{bold=true, foreground=hl_colors.NonText}} ) + end) + + it('is off by default', function() + insert("some text\nmore text") + feed("gg/text<cr>") + screen:expect([[ + some ^text | + more text | + ~ | + ~ | + ~ | + ~ | + /text | + ]]) + end) + + it('works', function() + execute('set hlsearch') + insert([[ + some text + more textstuff + stupidtexttextstuff + a text word + ]]) + feed("gg/text<cr>") + screen:expect([[ + some {1:^text} | + more {1:text}stuff | + stupid{1:texttext}stuff | + a {1:text} word | + | + ~ | + /text | + ]]) + + -- overlapping matches not allowed + feed("3nx") + screen:expect([[ + some {1:text} | + more {1:text}stuff | + stupid{1:text}^extstuff | + a {1:text} word | + | + ~ | + /text | + ]]) + + feed("ggn*") -- search for entire word + screen:expect([[ + some {1:text} | + more textstuff | + stupidtextextstuff | + a {1:^text} word | + | + ~ | + /\<text\> | + ]]) + + execute("nohlsearch") + screen:expect([[ + some text | + more textstuff | + stupidtextextstuff | + a ^text word | + | + ~ | + :nohlsearch | + ]]) + end) + + it('works with incsearch', function() + execute('set hlsearch') + execute('set incsearch') + insert([[ + the first line + in a little file + ]]) + feed("gg/li") + screen:expect([[ + the first {2:li}ne | + in a little file | + | + ~ | + ~ | + ~ | + /li^ | + ]]) + + feed("t") + screen:expect([[ + the first line | + in a {2:lit}tle file | + | + ~ | + ~ | + ~ | + /lit^ | + ]]) + + feed("<cr>") + screen:expect([[ + the first line | + in a {1:^lit}tle file | + | + ~ | + ~ | + ~ | + /lit | + ]]) + + feed("/fir") + screen:expect([[ + the {2:fir}st line | + in a {1:lit}tle file | + | + ~ | + ~ | + ~ | + /fir^ | + ]]) + + -- incsearch have priority over hlsearch + feed("<esc>/ttle") + screen:expect([[ + the first line | + in a {1:li}{2:ttle} file | + | + ~ | + ~ | + ~ | + /ttle^ | + ]]) + end) + + it('works with multiline regexps', function() + execute('set hlsearch') + feed('4oa repeated line<esc>') + feed('/line\\na<cr>') + screen:expect([[ + | + a repeated {1:^line} | + {1:a} repeated {1:line} | + {1:a} repeated {1:line} | + {1:a} repeated line | + ~ | + {3:search hit BOTTOM, continuing at TOP} | + ]]) + + -- it redraws rows above the changed one + feed('4Grb') + screen:expect([[ + | + a repeated {1:line} | + {1:a} repeated line | + ^b repeated {1:line} | + {1:a} repeated line | + ~ | + {3:search hit BOTTOM, continuing at TOP} | + ]]) + end) + + it('works with matchadd and syntax', function() + execute('set hlsearch') + insert([[ + very special text + ]]) + execute("syntax on") + execute("highlight MyGroup guibg=Green gui=bold") + execute("highlight MyGroup2 guibg=Magenta gui=italic") + execute("call matchadd('MyGroup', 'special')") + execute("call matchadd('MyGroup2', 'text', 0)") + + -- searchhl and matchadd matches are exclusive, only the higest priority + -- is used (and matches with lower priorities are not combined) + execute("/ial te") + screen:expect([[ + very {4:spec^ial}{1: te}{5:xt} | + | + ~ | + ~ | + ~ | + ~ | + {3:search hit BOTTOM, continuing at TOP} | + ]], {[1] = {background = hl_colors.Search}, [2] = {reverse = true}, + [3] = {foreground = hl_colors.Message}, [4] = {bold = true, background = + colors.Green}, [5] = {italic = true, background = colors.Magenta}}) + + execute("call clearmatches()") + screen:expect([[ + very spec{1:^ial te}xt | + | + ~ | + ~ | + ~ | + ~ | + :call clearmatches() | + ]]) + + -- searchhl has priority over syntax, but in this case + -- nonconflicting attributes are combined + execute("syntax keyword MyGroup special") + screen:expect([[ + very {4:spec}{5:^ial}{1: te}xt | + | + ~ | + ~ | + ~ | + ~ | + :syntax keyword MyGroup special | + ]], {[1] = {background = hl_colors.Search}, [2] = {reverse = true}, + [3] = {foreground = hl_colors.Message}, [4] = {bold = true, + background = colors.Green}, [5] = {bold = true, background = hl_colors.Search}}) + + end) +end) + |