test_display.vim 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. " Test for displaying stuff
  2. " Nvim: `:set term` is not supported.
  3. " if !has('gui_running') && has('unix')
  4. " set term=ansi
  5. " endif
  6. source view_util.vim
  7. source check.vim
  8. source screendump.vim
  9. func Test_display_foldcolumn()
  10. CheckFeature folding
  11. new
  12. vnew
  13. vert resize 25
  14. call assert_equal(25, winwidth(winnr()))
  15. set isprint=@
  16. 1put='e more noise blah blah‚ more stuff here'
  17. let expect = [
  18. \ "e more noise blah blah<82",
  19. \ "> more stuff here "
  20. \ ]
  21. call cursor(2, 1)
  22. norm! zt
  23. let lines = ScreenLines([1,2], winwidth(0))
  24. call assert_equal(expect, lines)
  25. set fdc=2
  26. let lines = ScreenLines([1,2], winwidth(0))
  27. let expect = [
  28. \ " e more noise blah blah<",
  29. \ " 82> more stuff here "
  30. \ ]
  31. call assert_equal(expect, lines)
  32. quit!
  33. quit!
  34. endfunc
  35. func Test_display_foldtext_mbyte()
  36. CheckFeature folding
  37. call NewWindow(10, 40)
  38. call append(0, range(1,20))
  39. exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2"
  40. call cursor(2, 1)
  41. norm! zf13G
  42. let lines=ScreenLines([1,3], winwidth(0)+1)
  43. let expect=[
  44. \ " 1 \u2502",
  45. \ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502",
  46. \ " 14 \u2502",
  47. \ ]
  48. call assert_equal(expect, lines)
  49. set fillchars=fold:-,vert:\|
  50. let lines=ScreenLines([1,3], winwidth(0)+1)
  51. let expect=[
  52. \ " 1 |",
  53. \ "+ +-- 12 lines: 2". repeat("-", 23). "|",
  54. \ " 14 |",
  55. \ ]
  56. call assert_equal(expect, lines)
  57. set foldtext& fillchars& foldmethod& fdc&
  58. bw!
  59. endfunc
  60. " check that win_ins_lines() and win_del_lines() work when t_cs is empty.
  61. func Test_scroll_without_region()
  62. CheckScreendump
  63. let lines =<< trim END
  64. call setline(1, range(1, 20))
  65. set t_cs=
  66. set laststatus=2
  67. END
  68. call writefile(lines, 'Xtestscroll', 'D')
  69. let buf = RunVimInTerminal('-S Xtestscroll', #{rows: 10})
  70. call VerifyScreenDump(buf, 'Test_scroll_no_region_1', {})
  71. call term_sendkeys(buf, ":3delete\<cr>")
  72. call VerifyScreenDump(buf, 'Test_scroll_no_region_2', {})
  73. call term_sendkeys(buf, ":4put\<cr>")
  74. call VerifyScreenDump(buf, 'Test_scroll_no_region_3', {})
  75. call term_sendkeys(buf, ":undo\<cr>")
  76. call term_sendkeys(buf, ":undo\<cr>")
  77. call term_sendkeys(buf, ":set laststatus=0\<cr>")
  78. call VerifyScreenDump(buf, 'Test_scroll_no_region_4', {})
  79. call term_sendkeys(buf, ":3delete\<cr>")
  80. call VerifyScreenDump(buf, 'Test_scroll_no_region_5', {})
  81. call term_sendkeys(buf, ":4put\<cr>")
  82. call VerifyScreenDump(buf, 'Test_scroll_no_region_6', {})
  83. " clean up
  84. call StopVimInTerminal(buf)
  85. endfunc
  86. func Test_display_listchars_precedes()
  87. call NewWindow(10, 10)
  88. " Need a physical line that wraps over the complete
  89. " window size
  90. call append(0, repeat('aaa aaa aa ', 10))
  91. call append(1, repeat(['bbb bbb bbb bbb'], 2))
  92. " remove blank trailing line
  93. $d
  94. set list nowrap
  95. call cursor(1, 1)
  96. " move to end of line and scroll 2 characters back
  97. norm! $2zh
  98. let lines=ScreenLines([1,4], winwidth(0)+1)
  99. let expect = [
  100. \ " aaa aa $ |",
  101. \ "$ |",
  102. \ "$ |",
  103. \ "~ |",
  104. \ ]
  105. call assert_equal(expect, lines)
  106. set list listchars+=precedes:< nowrap
  107. call cursor(1, 1)
  108. " move to end of line and scroll 2 characters back
  109. norm! $2zh
  110. let lines = ScreenLines([1,4], winwidth(0)+1)
  111. let expect = [
  112. \ "<aaa aa $ |",
  113. \ "< |",
  114. \ "< |",
  115. \ "~ |",
  116. \ ]
  117. call assert_equal(expect, lines)
  118. set wrap
  119. call cursor(1, 1)
  120. " the complete line should be displayed in the window
  121. norm! $
  122. let lines = ScreenLines([1,10], winwidth(0)+1)
  123. let expect = [
  124. \ "<aaa aaa a|",
  125. \ "a aaa aaa |",
  126. \ "aa aaa aaa|",
  127. \ " aa aaa aa|",
  128. \ "a aa aaa a|",
  129. \ "aa aa aaa |",
  130. \ "aaa aa aaa|",
  131. \ " aaa aa aa|",
  132. \ "a aaa aa a|",
  133. \ "aa aaa aa |",
  134. \ ]
  135. call assert_equal(expect, lines)
  136. set list& listchars& wrap&
  137. bw!
  138. endfunc
  139. " Check that win_lines() works correctly with the number_only parameter=TRUE
  140. " should break early to optimize cost of drawing, but needs to make sure
  141. " that the number column is correctly highlighted.
  142. func Test_scroll_CursorLineNr_update()
  143. CheckScreendump
  144. let lines =<< trim END
  145. hi CursorLineNr ctermfg=73 ctermbg=236
  146. set nu rnu cursorline cursorlineopt=number
  147. exe ":norm! o\<esc>110ia\<esc>"
  148. END
  149. let filename = 'Xdrawscreen'
  150. call writefile(lines, filename, 'D')
  151. let buf = RunVimInTerminal('-S '.filename, #{rows: 5, cols: 50})
  152. call term_sendkeys(buf, "k")
  153. call VerifyScreenDump(buf, 'Test_winline_rnu', {})
  154. " clean up
  155. call StopVimInTerminal(buf)
  156. endfunc
  157. " check a long file name does not result in the hit-enter prompt
  158. func Test_edit_long_file_name()
  159. CheckScreendump
  160. let longName = 'x'->repeat(min([&columns, 255]))
  161. call writefile([], longName, 'D')
  162. let buf = RunVimInTerminal('-N -u NONE ' .. longName, #{rows: 8})
  163. call VerifyScreenDump(buf, 'Test_long_file_name_1', {})
  164. " clean up
  165. call StopVimInTerminal(buf)
  166. endfunc
  167. func Test_unprintable_fileformats()
  168. CheckScreendump
  169. call writefile(["unix\r", "two"], 'Xunix.txt', 'D')
  170. call writefile(["mac\r", "two"], 'Xmac.txt', 'D')
  171. let lines =<< trim END
  172. edit Xunix.txt
  173. split Xmac.txt
  174. edit ++ff=mac
  175. END
  176. let filename = 'Xunprintable'
  177. call writefile(lines, filename, 'D')
  178. let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50})
  179. call VerifyScreenDump(buf, 'Test_display_unprintable_01', {})
  180. call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>")
  181. call VerifyScreenDump(buf, 'Test_display_unprintable_02', {})
  182. " clean up
  183. call StopVimInTerminal(buf)
  184. endfunc
  185. func Test_display_scroll_at_topline()
  186. CheckScreendump
  187. let buf = RunVimInTerminal('', #{cols: 20})
  188. call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>")
  189. call term_wait(buf)
  190. call term_sendkeys(buf, "O\<Esc>")
  191. call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
  192. call StopVimInTerminal(buf)
  193. endfunc
  194. func Test_display_scroll_update_visual()
  195. CheckScreendump
  196. let lines =<< trim END
  197. set scrolloff=0
  198. call setline(1, repeat(['foo'], 10))
  199. call sign_define('foo', { 'text': '>' })
  200. call sign_place(1, 'bar', 'foo', bufnr(), { 'lnum': 2 })
  201. call sign_place(2, 'bar', 'foo', bufnr(), { 'lnum': 1 })
  202. autocmd CursorMoved * if getcurpos()[1] == 2 | call sign_unplace('bar', { 'id': 1 }) | endif
  203. END
  204. call writefile(lines, 'XupdateVisual.vim', 'D')
  205. let buf = RunVimInTerminal('-S XupdateVisual.vim', #{rows: 8, cols: 60})
  206. call term_sendkeys(buf, "VG7kk")
  207. call VerifyScreenDump(buf, 'Test_display_scroll_update_visual', {})
  208. call StopVimInTerminal(buf)
  209. endfunc
  210. " Test for 'eob' (EndOfBuffer) item in 'fillchars'
  211. func Test_eob_fillchars()
  212. " default value
  213. " call assert_match('eob:\~', &fillchars)
  214. " invalid values
  215. call assert_fails(':set fillchars=eob:', 'E1511:')
  216. call assert_fails(':set fillchars=eob:xy', 'E1511:')
  217. call assert_fails(':set fillchars=eob:\255', 'E1511:')
  218. call assert_fails(':set fillchars=eob:<ff>', 'E1511:')
  219. call assert_fails(":set fillchars=eob:\x01", 'E1512:')
  220. call assert_fails(':set fillchars=eob:\\x01', 'E1512:')
  221. " default is ~
  222. new
  223. redraw
  224. call assert_equal('~', Screenline(2))
  225. set fillchars=eob:+
  226. redraw
  227. call assert_equal('+', Screenline(2))
  228. set fillchars=eob:\
  229. redraw
  230. call assert_equal(' ', nr2char(screenchar(2, 1)))
  231. set fillchars&
  232. close
  233. endfunc
  234. " Test for 'foldopen', 'foldclose' and 'foldsep' in 'fillchars'
  235. func Test_fold_fillchars()
  236. new
  237. set fdc=2 foldenable foldmethod=manual
  238. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  239. 2,4fold
  240. " First check for the default setting for a closed fold
  241. let lines = ScreenLines([1, 3], 8)
  242. let expected = [
  243. \ ' one ',
  244. \ '+ +-- 3',
  245. \ ' five '
  246. \ ]
  247. call assert_equal(expected, lines)
  248. normal 2Gzo
  249. " check the characters for an open fold
  250. let lines = ScreenLines([1, 5], 8)
  251. let expected = [
  252. \ ' one ',
  253. \ '- two ',
  254. \ '| three ',
  255. \ '| four ',
  256. \ ' five '
  257. \ ]
  258. call assert_equal(expected, lines)
  259. " change the setting
  260. set fillchars=vert:\|,fold:-,eob:~,foldopen:[,foldclose:],foldsep:-
  261. " check the characters for an open fold
  262. let lines = ScreenLines([1, 5], 8)
  263. let expected = [
  264. \ ' one ',
  265. \ '[ two ',
  266. \ '- three ',
  267. \ '- four ',
  268. \ ' five '
  269. \ ]
  270. call assert_equal(expected, lines)
  271. " check the characters for a closed fold
  272. normal 2Gzc
  273. let lines = ScreenLines([1, 3], 8)
  274. let expected = [
  275. \ ' one ',
  276. \ '] +-- 3',
  277. \ ' five '
  278. \ ]
  279. call assert_equal(expected, lines)
  280. %bw!
  281. set fillchars& fdc& foldmethod& foldenable&
  282. endfunc
  283. func Test_local_fillchars()
  284. CheckScreendump
  285. let lines =<< trim END
  286. call setline(1, ['window 1']->repeat(3))
  287. setlocal fillchars=stl:1,stlnc:a,vert:=,eob:x
  288. vnew
  289. call setline(1, ['window 2']->repeat(3))
  290. setlocal fillchars=stl:2,stlnc:b,vert:+,eob:y
  291. new
  292. wincmd J
  293. call setline(1, ['window 3']->repeat(3))
  294. setlocal fillchars=stl:3,stlnc:c,vert:<,eob:z
  295. vnew
  296. call setline(1, ['window 4']->repeat(3))
  297. setlocal fillchars=stl:4,stlnc:d,vert:>,eob:o
  298. END
  299. call writefile(lines, 'Xdisplayfillchars', 'D')
  300. let buf = RunVimInTerminal('-S Xdisplayfillchars', #{rows: 12})
  301. call VerifyScreenDump(buf, 'Test_display_fillchars_1', {})
  302. call term_sendkeys(buf, ":wincmd k\r")
  303. call VerifyScreenDump(buf, 'Test_display_fillchars_2', {})
  304. call StopVimInTerminal(buf)
  305. endfunc
  306. func Test_display_linebreak_breakat()
  307. new
  308. vert resize 25
  309. let _breakat = &breakat
  310. setl signcolumn=yes linebreak breakat=) showbreak=++
  311. call setline(1, repeat('x', winwidth(0) - 2) .. ')abc')
  312. let lines = ScreenLines([1, 2], 25)
  313. let expected = [
  314. \ ' xxxxxxxxxxxxxxxxxxxxxxx',
  315. \ ' ++)abc ',
  316. \ ]
  317. call assert_equal(expected, lines)
  318. setl breakindent breakindentopt=shift:2
  319. let lines = ScreenLines([1, 2], 25)
  320. let expected = [
  321. \ ' xxxxxxxxxxxxxxxxxxxxxxx',
  322. \ ' ++)abc ',
  323. \ ]
  324. call assert_equal(expected, lines)
  325. %bw!
  326. let &breakat=_breakat
  327. endfunc
  328. func Run_Test_display_lastline(euro)
  329. let lines =<< trim END
  330. call setline(1, ['aaa', 'b'->repeat(200)])
  331. set display=truncate
  332. vsplit
  333. 100wincmd <
  334. END
  335. if a:euro != ''
  336. let lines[2] = 'set fillchars=vert:\|,lastline:€'
  337. endif
  338. call writefile(lines, 'XdispLastline', 'D')
  339. let buf = RunVimInTerminal('-S XdispLastline', #{rows: 10})
  340. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}1', {})
  341. call term_sendkeys(buf, ":set display=lastline\<CR>")
  342. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}2', {})
  343. call term_sendkeys(buf, ":100wincmd >\<CR>")
  344. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}3', {})
  345. call term_sendkeys(buf, ":set display=truncate\<CR>")
  346. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}4', {})
  347. call term_sendkeys(buf, ":close\<CR>")
  348. call term_sendkeys(buf, ":3split\<CR>")
  349. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}5', {})
  350. call term_sendkeys(buf, ":close\<CR>")
  351. call term_sendkeys(buf, ":2vsplit\<CR>")
  352. call VerifyScreenDump(buf, $'Test_display_lastline_{a:euro}6', {})
  353. call StopVimInTerminal(buf)
  354. endfunc
  355. func Test_display_lastline_dump()
  356. CheckScreendump
  357. call Run_Test_display_lastline('')
  358. call Run_Test_display_lastline('euro_')
  359. endfunc
  360. func Test_display_lastline_fails()
  361. call assert_fails(':set fillchars=lastline:', 'E1511:')
  362. call assert_fails(':set fillchars=lastline:〇', 'E1512:')
  363. endfunc
  364. func Test_display_long_lastline()
  365. CheckScreendump
  366. let lines =<< trim END
  367. set display=lastline smoothscroll scrolloff=0
  368. call setline(1, [
  369. \'aaaaa'->repeat(150),
  370. \'bbbbb '->repeat(7) .. 'ccccc '->repeat(7) .. 'ddddd '->repeat(7)
  371. \])
  372. END
  373. call writefile(lines, 'XdispLongline', 'D')
  374. let buf = RunVimInTerminal('-S XdispLongline', #{rows: 14, cols: 35})
  375. call term_sendkeys(buf, "736|")
  376. call VerifyScreenDump(buf, 'Test_display_long_line_1', {})
  377. " The correct part of the last line is moved into view.
  378. call term_sendkeys(buf, "D")
  379. call VerifyScreenDump(buf, 'Test_display_long_line_2', {})
  380. " "w_skipcol" does not change because the topline is still long enough
  381. " to maintain the current skipcol.
  382. call term_sendkeys(buf, "g04l11gkD")
  383. call VerifyScreenDump(buf, 'Test_display_long_line_3', {})
  384. " "w_skipcol" is reset to bring the entire topline into view because
  385. " the line length is now smaller than the current skipcol + marker.
  386. call term_sendkeys(buf, "x")
  387. call VerifyScreenDump(buf, 'Test_display_long_line_4', {})
  388. call StopVimInTerminal(buf)
  389. endfunc
  390. " Moving the cursor to a line that doesn't fit in the window should show
  391. " correctly.
  392. func Test_display_cursor_long_line()
  393. CheckScreendump
  394. let lines =<< trim END
  395. call setline(1, ['a', 'b ' .. 'bbbbb'->repeat(150), 'c'])
  396. norm $j
  397. END
  398. call writefile(lines, 'XdispCursorLongline', 'D')
  399. let buf = RunVimInTerminal('-S XdispCursorLongline', #{rows: 8})
  400. call VerifyScreenDump(buf, 'Test_display_cursor_long_line_1', {})
  401. " FIXME: moving the cursor above the topline does not set w_skipcol
  402. " correctly with cpo+=n and zero scrolloff (curs_columns() extra == 1).
  403. call term_sendkeys(buf, ":set number cpo+=n scrolloff=0\<CR>")
  404. call term_sendkeys(buf, '$0')
  405. call VerifyScreenDump(buf, 'Test_display_cursor_long_line_2', {})
  406. " Going to the start of the line with "b" did not set w_skipcol correctly
  407. " with 'smoothscroll'.
  408. call term_sendkeys(buf, ":set smoothscroll\<CR>")
  409. call term_sendkeys(buf, '$b')
  410. call VerifyScreenDump(buf, 'Test_display_cursor_long_line_3', {})
  411. " Same for "ge".
  412. call term_sendkeys(buf, '$ge')
  413. call VerifyScreenDump(buf, 'Test_display_cursor_long_line_4', {})
  414. call StopVimInTerminal(buf)
  415. endfunc
  416. " vim: shiftwidth=2 sts=2 expandtab