diff options
-rw-r--r-- | src/nvim/testdir/test63.in | 195 | ||||
-rw-r--r-- | src/nvim/testdir/test63.ok | 16 | ||||
-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 |
5 files changed, 383 insertions, 212 deletions
diff --git a/src/nvim/testdir/test63.in b/src/nvim/testdir/test63.in deleted file mode 100644 index 7fbe0ac434..0000000000 --- a/src/nvim/testdir/test63.in +++ /dev/null @@ -1,195 +0,0 @@ -Test for ":match", ":2match", ":3match", "clearmatches()", "getmatches()", -"matchadd()", "matchaddpos()", "matcharg()", "matchdelete()", and "setmatches()". - -STARTTEST -:so small.vim -:set encoding=utf8 -:" --- Check that "matcharg()" returns the correct group and pattern if a match -:" --- is defined. -:let @r = "*** Test 1: " -:highlight MyGroup1 term=bold ctermbg=red guibg=red -:highlight MyGroup2 term=italic ctermbg=green guibg=green -:highlight MyGroup3 term=underline ctermbg=blue guibg=blue -:match MyGroup1 /TODO/ -:2match MyGroup2 /FIXME/ -:3match MyGroup3 /XXX/ -:if matcharg(1) == ['MyGroup1', 'TODO'] && matcharg(2) == ['MyGroup2', 'FIXME'] && matcharg(3) == ['MyGroup3', 'XXX'] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:" --- Check that "matcharg()" returns an empty list if the argument is not 1, -:" --- 2 or 3 (only 0 and 4 are tested). -:let @r .= "*** Test 2: " -:if matcharg(0) == [] && matcharg(4) == [] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:" --- Check that "matcharg()" returns ['', ''] if a match is not defined. -:let @r .= "*** Test 3: " -:match -:2match -:3match -:if matcharg(1) == ['', ''] && matcharg(2) == ['', ''] && matcharg(3) == ['', ''] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:" --- Check that "matchadd()" and "getmatches()" agree on added matches and -:" --- that default values apply. -:let @r .= "*** Test 4: " -:let m1 = matchadd("MyGroup1", "TODO") -:let m2 = matchadd("MyGroup2", "FIXME", 42) -:let m3 = matchadd("MyGroup3", "XXX", 60, 17) -:if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 4}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 5}, {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:" --- Check that "matchdelete()" deletes the matches defined in the previous -:" --- test correctly. -:let @r .= "*** Test 5: " -:call matchdelete(m1) -:call matchdelete(m2) -:call matchdelete(m3) -:unlet m1 -:unlet m2 -:unlet m3 -:if getmatches() == [] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:" --- Check that "matchdelete()" returns 0 if successful and otherwise -1. -:let @r .= "*** Test 6: " -:let m = matchadd("MyGroup1", "TODO") -:let r1 = matchdelete(m) -:let r2 = matchdelete(42) -:if r1 == 0 && r2 == -1 -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:unlet m -:unlet r1 -:unlet r2 -:" --- Check that "clearmatches()" clears all matches defined by ":match" and -:" --- "matchadd()". -:let @r .= "*** Test 7: " -:let m1 = matchadd("MyGroup1", "TODO") -:let m2 = matchadd("MyGroup2", "FIXME", 42) -:let m3 = matchadd("MyGroup3", "XXX", 60, 17) -:match MyGroup1 /COFFEE/ -:2match MyGroup2 /HUMPPA/ -:3match MyGroup3 /VIM/ -:call clearmatches() -:if getmatches() == [] -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:unlet m1 -:unlet m2 -:unlet m3 -:" --- Check that "setmatches()" restores a list of matches saved by -:" --- "getmatches()" without changes. (Matches with equal priority must also -:" --- remain in the same order.) -:let @r .= "*** Test 8: " -:let m1 = matchadd("MyGroup1", "TODO") -:let m2 = matchadd("MyGroup2", "FIXME", 42) -:let m3 = matchadd("MyGroup3", "XXX", 60, 17) -:match MyGroup1 /COFFEE/ -:2match MyGroup2 /HUMPPA/ -:3match MyGroup3 /VIM/ -:let ml = getmatches() -:call clearmatches() -:call setmatches(ml) -:if getmatches() == ml -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:call clearmatches() -:unlet m1 -:unlet m2 -:unlet m3 -:unlet ml -:" --- 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). -:let @r .= "*** Test 9: " -:let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}]) -:if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}] && r1 == 0 -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:call clearmatches() -:unlet r1 -:" --- 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.) -:let @r .= "*** Test 10: " -:let rs1 = setmatches([]) -:let rs2 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}]) -:call clearmatches() -:let rf1 = setmatches(0) -:let rf2 = setmatches([0]) -:let rf3 = setmatches([{'wrong key': 'wrong value'}]) -:if rs1 == 0 && rs2 == 0 && rf1 == -1 && rf2 == -1 && rf3 == -1 -: let @r .= "OK\n" -:else -: let @r .= "FAILED\n" -:endif -:unlet rs1 -:unlet rs2 -:unlet rf1 -:unlet rf2 -:unlet rf3 -:" --- Check that "matchaddpos()" positions matches correctly -:let @r .= "*** Test 11:\n" -:set nolazyredraw -:call setline(1, 'abcdefghijklmnopq') -:call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3) -:1 -:redraw! -:let v1 = screenattr(1, 1) -:let v5 = screenattr(1, 5) -:let v6 = screenattr(1, 6) -:let v8 = screenattr(1, 8) -:let v10 = screenattr(1, 10) -:let v11 = screenattr(1, 11) -:let @r .= string(getmatches())."\n" -:if v1 != v5 && v6 == v1 && v8 == v5 && v10 == v5 && v11 == v1 -: let @r .= "OK\n" -:else -: let @r .= "FAILED: " . v5 . "/" . v6 . "/" . v8 . "/" . v10 . "/" . v11 . "\n" -:endif -:call clearmatches() -:" -:call setline(1, 'abcdΣabcdef') -:call matchaddpos("MyGroup1", [[1, 4, 2], [1, 9, 2]]) -:1 -:redraw! -:let v1 = screenattr(1, 1) -:let v4 = screenattr(1, 4) -:let v5 = screenattr(1, 5) -:let v6 = screenattr(1, 6) -:let v7 = screenattr(1, 7) -:let v8 = screenattr(1, 8) -:let v9 = screenattr(1, 9) -:let v10 = screenattr(1, 10) -:let @r .= string(getmatches())."\n" -:if v1 != v4 && v5 == v4 && v6 == v1 && v7 == v1 && v8 == v4 && v9 == v4 && v10 == v1 -: let @r .= "OK\n" -:else -: let @r .= "FAILED: " . v4 . "/" . v5 . "/" . v6 . "/" . v7 . "/" . v8 . "/" . v9 . "/" . v10 . "\n" -:endif -:call clearmatches() -G"rp -:/^Results/,$wq! test.out -ENDTEST - -Results of test63: diff --git a/src/nvim/testdir/test63.ok b/src/nvim/testdir/test63.ok deleted file mode 100644 index 5d619395b7..0000000000 --- a/src/nvim/testdir/test63.ok +++ /dev/null @@ -1,16 +0,0 @@ -Results of test63: -*** Test 1: OK -*** Test 2: OK -*** Test 3: OK -*** Test 4: OK -*** Test 5: OK -*** Test 6: OK -*** Test 7: OK -*** Test 8: OK -*** Test 9: OK -*** Test 10: OK -*** Test 11: -[{'group': 'MyGroup1', 'id': 3, 'priority': 10, 'pos1': [1, 5, 1], 'pos2': [1, 8, 3]}] -OK -[{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}] -OK 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) + |