diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/legacy/063_match_and_matchadd_spec.lua | 141 | ||||
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/ui/searchhl_spec.lua | 241 |
3 files changed, 383 insertions, 1 deletions
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/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) + |