blob: 61cd9839c0c32cbb762b37a61f5695356a26bb3b [file] [log] [blame]
Bram Moolenaar410e98a2019-09-09 22:05:49 +02001" Test for cursorline and cursorlineopt
Bram Moolenaar017ba072019-09-14 21:01:23 +02002
Bram Moolenaar410e98a2019-09-09 22:05:49 +02003source check.vim
Bram Moolenaar017ba072019-09-14 21:01:23 +02004source screendump.vim
Bram Moolenaar410e98a2019-09-09 22:05:49 +02005
6function! s:screen_attr(lnum) abort
7 return map(range(1, 8), 'screenattr(a:lnum, v:val)')
8endfunction
9
10function! s:test_windows(h, w) abort
11 call NewWindow(a:h, a:w)
12endfunction
13
14function! s:close_windows() abort
15 call CloseWindow()
16endfunction
17
18function! s:new_hi() abort
19 redir => save_hi
20 silent! hi CursorLineNr
21 redir END
22 let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '')
23 exe 'hi' save_hi 'ctermbg=0 guibg=Black'
24 return save_hi
25endfunction
26
27func Test_cursorline_highlight1()
28 let save_hi = s:new_hi()
29 try
30 call s:test_windows(10, 20)
31 call setline(1, repeat(['aaaa'], 10))
32 redraw
33 let attr01 = s:screen_attr(1)
34 call assert_equal(repeat([attr01[0]], 8), attr01)
35
36 setl number numberwidth=4
37 redraw
38 let attr11 = s:screen_attr(1)
39 call assert_equal(repeat([attr11[0]], 4), attr11[0:3])
40 call assert_equal(repeat([attr11[4]], 4), attr11[4:7])
41 call assert_notequal(attr11[0], attr11[4])
42
43 setl cursorline
44 redraw
45 let attr21 = s:screen_attr(1)
46 let attr22 = s:screen_attr(2)
47 call assert_equal(repeat([attr21[0]], 4), attr21[0:3])
48 call assert_equal(repeat([attr21[4]], 4), attr21[4:7])
49 call assert_equal(attr11, attr22)
50 call assert_notequal(attr22, attr21)
51
52 setl nocursorline relativenumber
53 redraw
54 let attr31 = s:screen_attr(1)
Bram Moolenaar49474ca2019-10-05 21:57:12 +020055 call assert_equal(attr22[0:3], attr31[0:3])
Bram Moolenaar410e98a2019-09-09 22:05:49 +020056 call assert_equal(attr11[4:7], attr31[4:7])
57
58 call s:close_windows()
59 finally
60 exe 'hi' save_hi
61 endtry
62endfunc
63
64func Test_cursorline_highlight2()
65 CheckOption cursorlineopt
66
67 let save_hi = s:new_hi()
68 try
69 call s:test_windows(10, 20)
70 call setline(1, repeat(['aaaa'], 10))
71 redraw
72 let attr0 = s:screen_attr(1)
73 call assert_equal(repeat([attr0[0]], 8), attr0)
74
75 setl number
76 redraw
77 let attr1 = s:screen_attr(1)
78 call assert_notequal(attr0[0:3], attr1[0:3])
79 call assert_equal(attr0[0:3], attr1[4:7])
80
81 setl cursorline cursorlineopt=both
82 redraw
83 let attr2 = s:screen_attr(1)
84 call assert_notequal(attr1[0:3], attr2[0:3])
85 call assert_notequal(attr1[4:7], attr2[4:7])
86
87 setl cursorlineopt=line
88 redraw
89 let attr3 = s:screen_attr(1)
90 call assert_equal(attr1[0:3], attr3[0:3])
91 call assert_equal(attr2[4:7], attr3[4:7])
92
93 setl cursorlineopt=number
94 redraw
95 let attr4 = s:screen_attr(1)
96 call assert_equal(attr2[0:3], attr4[0:3])
97 call assert_equal(attr1[4:7], attr4[4:7])
98
99 setl nonumber
100 redraw
101 let attr5 = s:screen_attr(1)
102 call assert_equal(attr0, attr5)
103
104 call s:close_windows()
105 finally
106 exe 'hi' save_hi
107 endtry
108endfunc
Bram Moolenaar017ba072019-09-14 21:01:23 +0200109
110func Test_cursorline_screenline()
111 CheckScreendump
112 CheckOption cursorlineopt
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200113
Bram Moolenaar017ba072019-09-14 21:01:23 +0200114 let filename='Xcursorline'
115 let lines = []
116
117 let file_content =<< trim END
118 1 foooooooo ar eins‍zwei drei vier fünf sechs sieben acht un zehn elf zwöfl dreizehn v ierzehn fünfzehn
119 2 foooooooo bar eins zwei drei vier fünf sechs sieben
120 3 foooooooo bar eins zwei drei vier fünf sechs sieben
121 4 foooooooo bar eins zwei drei vier fünf sechs sieben
122 END
123 let lines1 =<< trim END1
124 set nocp
125 set display=lastline
126 set cursorlineopt=screenline cursorline nu wrap sbr=>
127 hi CursorLineNr ctermfg=blue
128 25vsp
129 END1
130 let lines2 =<< trim END2
131 call cursor(1,1)
132 END2
133 call extend(lines, lines1)
134 call extend(lines, ["call append(0, ".. string(file_content).. ')'])
135 call extend(lines, lines2)
136 call writefile(lines, filename)
137 " basic test
138 let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200139 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200140 call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
141 call term_sendkeys(buf, "fagj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200142 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200143 call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
144 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200145 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200146 call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
147 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200148 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200149 call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
150 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200151 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200152 call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
153 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200154 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200155 call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
156 " test with set list and cursorlineopt containing number
157 call term_sendkeys(buf, "gg0")
158 call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
159 call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
160 call term_sendkeys(buf, "fagj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200161 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200162 call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
163 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200164 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200165 call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
166 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200167 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200168 call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
169 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200170 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200171 call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
172 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200173 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200174 call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
175 if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
176 " test with set foldcolumn signcoloumn and breakindent
177 call term_sendkeys(buf, "gg0")
178 call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
179 call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
180 call term_sendkeys(buf, "fagj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200181 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200182 call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
183 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200184 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200185 call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
186 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200187 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200188 call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
189 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200190 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200191 call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
192 call term_sendkeys(buf, "gj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200193 call TermWait(buf)
Bram Moolenaar017ba072019-09-14 21:01:23 +0200194 call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
195 endif
196
197 call StopVimInTerminal(buf)
198 call delete(filename)
199endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200200
Bram Moolenaarc9e7e342021-07-22 21:33:03 +0200201func Test_cursorline_redraw()
202 CheckScreendump
203 CheckOption cursorlineopt
204
205 let textlines =<< END
206 When the option is a list of flags, {value} must be
207 exactly as they appear in the option. Remove flags
208 one by one to avoid problems.
209 Also see |:set-args| above.
210
211The {option} arguments to ":set" may be repeated. For example: >
212 :set ai nosi sw=3 ts=3
213If you make an error in one of the arguments, an error message will be given
214and the following arguments will be ignored.
215
216 *:set-verbose*
217When 'verbose' is non-zero, displaying an option value will also tell where it
218was last set. Example: >
219 :verbose set shiftwidth cindent?
220< shiftwidth=4 ~
221 Last set from modeline line 1 ~
222 cindent ~
223 Last set from /usr/local/share/vim/vim60/ftplugin/c.vim line 30 ~
224This is only done when specific option values are requested, not for ":verbose
225set all" or ":verbose set" without an argument.
226When the option was set by hand there is no "Last set" message.
227When the option was set while executing a function, user command or
228END
229 call writefile(textlines, 'Xtextfile')
230
231 let script =<< trim END
232 set cursorline scrolloff=2
233 normal 12G
234 END
235 call writefile(script, 'Xscript')
236
237 let buf = RunVimInTerminal('-S Xscript Xtextfile', #{rows: 20, cols: 40})
238 call VerifyScreenDump(buf, 'Test_cursorline_redraw_1', {})
239 call term_sendkeys(buf, "zt")
240 call TermWait(buf)
241 call term_sendkeys(buf, "\<C-U>")
242 call VerifyScreenDump(buf, 'Test_cursorline_redraw_2', {})
243
244 call StopVimInTerminal(buf)
245 call delete('Xscript')
246 call delete('Xtextfile')
247endfunc
248
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200249" vim: shiftwidth=2 sts=2 expandtab