Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 1 | " Test for displaying stuff |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 3 | if !has('gui_running') && has('unix') |
| 4 | set term=ansi |
| 5 | endif |
| 6 | |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 7 | source view_util.vim |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 8 | source check.vim |
| 9 | source screendump.vim |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 10 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 11 | func Test_display_foldcolumn() |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 12 | CheckFeature folding |
| 13 | |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 14 | new |
| 15 | vnew |
| 16 | vert resize 25 |
Bram Moolenaar | 7089237 | 2016-12-09 19:51:49 +0100 | [diff] [blame] | 17 | call assert_equal(25, winwidth(winnr())) |
| 18 | set isprint=@ |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 19 | |
| 20 | 1put='e more noise blah blah‚ more stuff here' |
| 21 | |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 22 | let expect = [ |
| 23 | \ "e more noise blah blah<82", |
| 24 | \ "> more stuff here " |
| 25 | \ ] |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 26 | |
| 27 | call cursor(2, 1) |
| 28 | norm! zt |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 29 | let lines = ScreenLines([1,2], winwidth(0)) |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 30 | call assert_equal(expect, lines) |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 31 | set fdc=2 |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 32 | let lines = ScreenLines([1,2], winwidth(0)) |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 33 | let expect = [ |
| 34 | \ " e more noise blah blah<", |
| 35 | \ " 82> more stuff here " |
| 36 | \ ] |
| 37 | call assert_equal(expect, lines) |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 38 | |
| 39 | quit! |
| 40 | quit! |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 41 | endfunc |
| 42 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 43 | func Test_display_foldtext_mbyte() |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 44 | CheckFeature folding |
| 45 | |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 46 | call NewWindow(10, 40) |
| 47 | call append(0, range(1,20)) |
| 48 | exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2" |
| 49 | call cursor(2, 1) |
| 50 | norm! zf13G |
| 51 | let lines=ScreenLines([1,3], winwidth(0)+1) |
| 52 | let expect=[ |
| 53 | \ " 1 \u2502", |
| 54 | \ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502", |
| 55 | \ " 14 \u2502", |
| 56 | \ ] |
| 57 | call assert_equal(expect, lines) |
Bram Moolenaar | 8da1e6c | 2017-03-29 20:38:59 +0200 | [diff] [blame] | 58 | |
| 59 | set fillchars=fold:-,vert:\| |
| 60 | let lines=ScreenLines([1,3], winwidth(0)+1) |
| 61 | let expect=[ |
| 62 | \ " 1 |", |
| 63 | \ "+ +-- 12 lines: 2". repeat("-", 23). "|", |
| 64 | \ " 14 |", |
| 65 | \ ] |
| 66 | call assert_equal(expect, lines) |
| 67 | |
Bram Moolenaar | c6cd840 | 2017-03-29 14:40:47 +0200 | [diff] [blame] | 68 | set foldtext& fillchars& foldmethod& fdc& |
| 69 | bw! |
| 70 | endfunc |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 71 | |
| 72 | " check that win_ins_lines() and win_del_lines() work when t_cs is empty. |
| 73 | func Test_scroll_without_region() |
| 74 | CheckScreendump |
| 75 | |
| 76 | let lines =<< trim END |
| 77 | call setline(1, range(1, 20)) |
| 78 | set t_cs= |
| 79 | set laststatus=2 |
| 80 | END |
| 81 | call writefile(lines, 'Xtestscroll') |
| 82 | let buf = RunVimInTerminal('-S Xtestscroll', #{rows: 10}) |
| 83 | |
| 84 | call VerifyScreenDump(buf, 'Test_scroll_no_region_1', {}) |
| 85 | |
| 86 | call term_sendkeys(buf, ":3delete\<cr>") |
| 87 | call VerifyScreenDump(buf, 'Test_scroll_no_region_2', {}) |
| 88 | |
| 89 | call term_sendkeys(buf, ":4put\<cr>") |
| 90 | call VerifyScreenDump(buf, 'Test_scroll_no_region_3', {}) |
| 91 | |
Bram Moolenaar | 7cc5351 | 2019-08-03 23:30:21 +0200 | [diff] [blame] | 92 | call term_sendkeys(buf, ":undo\<cr>") |
| 93 | call term_sendkeys(buf, ":undo\<cr>") |
| 94 | call term_sendkeys(buf, ":set laststatus=0\<cr>") |
| 95 | call VerifyScreenDump(buf, 'Test_scroll_no_region_4', {}) |
| 96 | |
| 97 | call term_sendkeys(buf, ":3delete\<cr>") |
| 98 | call VerifyScreenDump(buf, 'Test_scroll_no_region_5', {}) |
| 99 | |
| 100 | call term_sendkeys(buf, ":4put\<cr>") |
| 101 | call VerifyScreenDump(buf, 'Test_scroll_no_region_6', {}) |
| 102 | |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 103 | " clean up |
| 104 | call StopVimInTerminal(buf) |
| 105 | call delete('Xtestscroll') |
| 106 | endfunc |
Bram Moolenaar | bffba7f | 2019-09-20 17:00:17 +0200 | [diff] [blame] | 107 | |
| 108 | func Test_display_listchars_precedes() |
| 109 | call NewWindow(10, 10) |
| 110 | " Need a physical line that wraps over the complete |
| 111 | " window size |
| 112 | call append(0, repeat('aaa aaa aa ', 10)) |
| 113 | call append(1, repeat(['bbb bbb bbb bbb'], 2)) |
| 114 | " remove blank trailing line |
| 115 | $d |
| 116 | set list nowrap |
| 117 | call cursor(1, 1) |
| 118 | " move to end of line and scroll 2 characters back |
| 119 | norm! $2zh |
| 120 | let lines=ScreenLines([1,4], winwidth(0)+1) |
| 121 | let expect = [ |
| 122 | \ " aaa aa $ |", |
| 123 | \ "$ |", |
| 124 | \ "$ |", |
| 125 | \ "~ |", |
| 126 | \ ] |
| 127 | call assert_equal(expect, lines) |
| 128 | set list listchars+=precedes:< nowrap |
| 129 | call cursor(1, 1) |
| 130 | " move to end of line and scroll 2 characters back |
| 131 | norm! $2zh |
| 132 | let lines = ScreenLines([1,4], winwidth(0)+1) |
| 133 | let expect = [ |
| 134 | \ "<aaa aa $ |", |
| 135 | \ "< |", |
| 136 | \ "< |", |
| 137 | \ "~ |", |
| 138 | \ ] |
| 139 | call assert_equal(expect, lines) |
| 140 | set wrap |
| 141 | call cursor(1, 1) |
| 142 | " the complete line should be displayed in the window |
| 143 | norm! $ |
| 144 | |
| 145 | let lines = ScreenLines([1,10], winwidth(0)+1) |
| 146 | let expect = [ |
| 147 | \ "<aaa aaa a|", |
| 148 | \ "a aaa aaa |", |
| 149 | \ "aa aaa aaa|", |
| 150 | \ " aa aaa aa|", |
| 151 | \ "a aa aaa a|", |
| 152 | \ "aa aa aaa |", |
| 153 | \ "aaa aa aaa|", |
| 154 | \ " aaa aa aa|", |
| 155 | \ "a aaa aa a|", |
| 156 | \ "aa aaa aa |", |
| 157 | \ ] |
| 158 | call assert_equal(expect, lines) |
| 159 | set list& listchars& wrap& |
| 160 | bw! |
| 161 | endfunc |
Bram Moolenaar | 2868668 | 2019-10-24 15:12:37 +0200 | [diff] [blame] | 162 | |
| 163 | " Check that win_lines() works correctly with the number_only parameter=TRUE |
| 164 | " should break early to optimize cost of drawing, but needs to make sure |
| 165 | " that the number column is correctly highlighted. |
| 166 | func Test_scroll_CursorLineNr_update() |
| 167 | CheckScreendump |
| 168 | |
| 169 | let lines =<< trim END |
| 170 | hi CursorLineNr ctermfg=73 ctermbg=236 |
| 171 | set nu rnu cursorline cursorlineopt=number |
| 172 | exe ":norm! o\<esc>110ia\<esc>" |
| 173 | END |
| 174 | let filename = 'Xdrawscreen' |
| 175 | call writefile(lines, filename) |
| 176 | let buf = RunVimInTerminal('-S '.filename, #{rows: 5, cols: 50}) |
| 177 | call term_sendkeys(buf, "k") |
Bram Moolenaar | 2868668 | 2019-10-24 15:12:37 +0200 | [diff] [blame] | 178 | call VerifyScreenDump(buf, 'Test_winline_rnu', {}) |
| 179 | |
| 180 | " clean up |
| 181 | call StopVimInTerminal(buf) |
| 182 | call delete(filename) |
| 183 | endfunc |
Bram Moolenaar | 0efd1bd | 2019-12-11 19:00:04 +0100 | [diff] [blame] | 184 | |
| 185 | " check a long file name does not result in the hit-enter prompt |
| 186 | func Test_edit_long_file_name() |
| 187 | CheckScreendump |
| 188 | |
Bram Moolenaar | 6e43b30 | 2019-12-14 17:53:27 +0100 | [diff] [blame] | 189 | let longName = 'x'->repeat(min([&columns, 255])) |
Bram Moolenaar | 0efd1bd | 2019-12-11 19:00:04 +0100 | [diff] [blame] | 190 | call writefile([], longName) |
| 191 | let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8}) |
| 192 | |
| 193 | call VerifyScreenDump(buf, 'Test_long_file_name_1', {}) |
| 194 | |
Bram Moolenaar | 0efd1bd | 2019-12-11 19:00:04 +0100 | [diff] [blame] | 195 | " clean up |
| 196 | call StopVimInTerminal(buf) |
| 197 | call delete(longName) |
| 198 | endfunc |
| 199 | |
Bram Moolenaar | 32ee627 | 2020-06-10 14:16:49 +0200 | [diff] [blame] | 200 | func Test_unprintable_fileformats() |
| 201 | CheckScreendump |
| 202 | |
| 203 | call writefile(["unix\r", "two"], 'Xunix.txt') |
| 204 | call writefile(["mac\r", "two"], 'Xmac.txt') |
| 205 | let lines =<< trim END |
| 206 | edit Xunix.txt |
| 207 | split Xmac.txt |
| 208 | edit ++ff=mac |
| 209 | END |
| 210 | let filename = 'Xunprintable' |
| 211 | call writefile(lines, filename) |
| 212 | let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50}) |
| 213 | call VerifyScreenDump(buf, 'Test_display_unprintable_01', {}) |
| 214 | call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>") |
| 215 | call VerifyScreenDump(buf, 'Test_display_unprintable_02', {}) |
| 216 | |
| 217 | " clean up |
| 218 | call StopVimInTerminal(buf) |
| 219 | call delete('Xunix.txt') |
| 220 | call delete('Xmac.txt') |
| 221 | call delete(filename) |
| 222 | endfunc |
Bram Moolenaar | f8992d4 | 2020-08-01 19:14:13 +0200 | [diff] [blame] | 223 | |
| 224 | " Test for scrolling that modifies buffer during visual block |
| 225 | func Test_visual_block_scroll() |
| 226 | CheckScreendump |
| 227 | |
| 228 | let lines =<< trim END |
| 229 | source $VIMRUNTIME/plugin/matchparen.vim |
| 230 | set scrolloff=1 |
| 231 | call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}']) |
| 232 | call cursor(5, 1) |
| 233 | END |
| 234 | |
| 235 | let filename = 'Xvisualblockmodifiedscroll' |
| 236 | call writefile(lines, filename) |
| 237 | |
| 238 | let buf = RunVimInTerminal('-S '.filename, #{rows: 7}) |
| 239 | call term_sendkeys(buf, "V\<C-D>\<C-D>") |
| 240 | |
| 241 | call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {}) |
| 242 | |
| 243 | call StopVimInTerminal(buf) |
| 244 | call delete(filename) |
| 245 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 246 | |
Bram Moolenaar | 9dc1917 | 2020-08-19 20:19:48 +0200 | [diff] [blame] | 247 | func Test_display_scroll_at_topline() |
| 248 | CheckScreendump |
| 249 | |
| 250 | let buf = RunVimInTerminal('', #{cols: 20}) |
| 251 | call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 252 | call TermWait(buf) |
Bram Moolenaar | 9dc1917 | 2020-08-19 20:19:48 +0200 | [diff] [blame] | 253 | call term_sendkeys(buf, "O\<Esc>") |
| 254 | call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4}) |
| 255 | |
| 256 | call StopVimInTerminal(buf) |
| 257 | endfunc |
| 258 | |
Bram Moolenaar | abb6fbd | 2022-03-25 15:42:27 +0000 | [diff] [blame] | 259 | func Test_display_scroll_update_visual() |
| 260 | CheckScreendump |
| 261 | |
| 262 | let lines =<< trim END |
| 263 | set scrolloff=0 |
| 264 | call setline(1, repeat(['foo'], 10)) |
| 265 | call sign_define('foo', { 'text': '>' }) |
| 266 | call sign_place(1, 'bar', 'foo', bufnr(), { 'lnum': 2 }) |
| 267 | call sign_place(2, 'bar', 'foo', bufnr(), { 'lnum': 1 }) |
| 268 | autocmd CursorMoved * if getcurpos()[1] == 2 | call sign_unplace('bar', { 'id': 1 }) | endif |
| 269 | END |
| 270 | call writefile(lines, 'XupdateVisual.vim') |
| 271 | |
| 272 | let buf = RunVimInTerminal('-S XupdateVisual.vim', #{rows: 8, cols: 60}) |
| 273 | call term_sendkeys(buf, "VG7kk") |
| 274 | call VerifyScreenDump(buf, 'Test_display_scroll_update_visual', {}) |
| 275 | |
| 276 | call StopVimInTerminal(buf) |
| 277 | call delete('XupdateVisual.vim') |
| 278 | endfunc |
| 279 | |
Bram Moolenaar | a98f8a2 | 2021-02-13 18:24:23 +0100 | [diff] [blame] | 280 | " Test for 'eob' (EndOfBuffer) item in 'fillchars' |
| 281 | func Test_eob_fillchars() |
| 282 | " default value |
| 283 | call assert_match('eob:\~', &fillchars) |
| 284 | " invalid values |
| 285 | call assert_fails(':set fillchars=eob:', 'E474:') |
| 286 | call assert_fails(':set fillchars=eob:xy', 'E474:') |
| 287 | call assert_fails(':set fillchars=eob:\255', 'E474:') |
| 288 | call assert_fails(':set fillchars=eob:<ff>', 'E474:') |
zeertzjq | 60618c8 | 2021-12-18 15:32:46 +0000 | [diff] [blame] | 289 | call assert_fails(":set fillchars=eob:\x01", 'E474:') |
| 290 | call assert_fails(':set fillchars=eob:\\x01', 'E474:') |
Bram Moolenaar | a98f8a2 | 2021-02-13 18:24:23 +0100 | [diff] [blame] | 291 | " default is ~ |
| 292 | new |
Bram Moolenaar | 2cec027 | 2021-03-22 17:30:47 +0100 | [diff] [blame] | 293 | redraw |
Bram Moolenaar | a98f8a2 | 2021-02-13 18:24:23 +0100 | [diff] [blame] | 294 | call assert_equal('~', Screenline(2)) |
| 295 | set fillchars=eob:+ |
Bram Moolenaar | 2cec027 | 2021-03-22 17:30:47 +0100 | [diff] [blame] | 296 | redraw |
Bram Moolenaar | a98f8a2 | 2021-02-13 18:24:23 +0100 | [diff] [blame] | 297 | call assert_equal('+', Screenline(2)) |
| 298 | set fillchars=eob:\ |
Bram Moolenaar | 2cec027 | 2021-03-22 17:30:47 +0100 | [diff] [blame] | 299 | redraw |
Bram Moolenaar | a98f8a2 | 2021-02-13 18:24:23 +0100 | [diff] [blame] | 300 | call assert_equal(' ', nr2char(screenchar(2, 1))) |
| 301 | set fillchars& |
| 302 | close |
| 303 | endfunc |
| 304 | |
Bram Moolenaar | 3aca5a6 | 2021-02-17 13:14:07 +0100 | [diff] [blame] | 305 | " Test for 'foldopen', 'foldclose' and 'foldsep' in 'fillchars' |
| 306 | func Test_fold_fillchars() |
| 307 | new |
| 308 | set fdc=2 foldenable foldmethod=manual |
| 309 | call setline(1, ['one', 'two', 'three', 'four', 'five']) |
| 310 | 2,4fold |
| 311 | " First check for the default setting for a closed fold |
| 312 | let lines = ScreenLines([1, 3], 8) |
| 313 | let expected = [ |
| 314 | \ ' one ', |
| 315 | \ '+ +-- 3', |
| 316 | \ ' five ' |
| 317 | \ ] |
| 318 | call assert_equal(expected, lines) |
| 319 | normal 2Gzo |
| 320 | " check the characters for an open fold |
| 321 | let lines = ScreenLines([1, 5], 8) |
| 322 | let expected = [ |
| 323 | \ ' one ', |
| 324 | \ '- two ', |
| 325 | \ '| three ', |
| 326 | \ '| four ', |
| 327 | \ ' five ' |
| 328 | \ ] |
| 329 | call assert_equal(expected, lines) |
| 330 | |
| 331 | " change the setting |
| 332 | set fillchars=vert:\|,fold:-,eob:~,foldopen:[,foldclose:],foldsep:- |
| 333 | |
| 334 | " check the characters for an open fold |
| 335 | let lines = ScreenLines([1, 5], 8) |
| 336 | let expected = [ |
| 337 | \ ' one ', |
| 338 | \ '[ two ', |
| 339 | \ '- three ', |
| 340 | \ '- four ', |
| 341 | \ ' five ' |
| 342 | \ ] |
| 343 | call assert_equal(expected, lines) |
| 344 | |
| 345 | " check the characters for a closed fold |
| 346 | normal 2Gzc |
| 347 | let lines = ScreenLines([1, 3], 8) |
| 348 | let expected = [ |
| 349 | \ ' one ', |
| 350 | \ '] +-- 3', |
| 351 | \ ' five ' |
| 352 | \ ] |
| 353 | call assert_equal(expected, lines) |
| 354 | |
| 355 | %bw! |
| 356 | set fillchars& fdc& foldmethod& foldenable& |
| 357 | endfunc |
| 358 | |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 359 | func Test_display_linebreak_breakat() |
| 360 | new |
| 361 | vert resize 25 |
| 362 | let _breakat = &breakat |
| 363 | setl signcolumn=yes linebreak breakat=) showbreak=+\ |
| 364 | call setline(1, repeat('x', winwidth(0) - 2) .. ')abc') |
| 365 | let lines = ScreenLines([1, 2], 25) |
| 366 | let expected = [ |
| 367 | \ ' xxxxxxxxxxxxxxxxxxxxxxx', |
| 368 | \ ' + )abc ' |
| 369 | \ ] |
| 370 | call assert_equal(expected, lines) |
| 371 | %bw! |
| 372 | let &breakat=_breakat |
| 373 | endfunc |
| 374 | |
| 375 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 376 | " vim: shiftwidth=2 sts=2 expandtab |