test_listlbr.vim 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. " Test for linebreak and list option (non-utf8)
  2. scriptencoding latin1
  3. source check.vim
  4. CheckOption linebreak
  5. CheckFeature conceal
  6. source view_util.vim
  7. source screendump.vim
  8. function s:screen_lines(lnum, width) abort
  9. return ScreenLines(a:lnum, a:width)
  10. endfunction
  11. func s:compare_lines(expect, actual)
  12. call assert_equal(a:expect, a:actual)
  13. endfunc
  14. function s:test_windows(...)
  15. call NewWindow(10, 20)
  16. setl ts=8 sw=4 sts=4 linebreak sbr= wrap
  17. exe get(a:000, 0, '')
  18. endfunction
  19. function s:close_windows(...)
  20. call CloseWindow()
  21. exe get(a:000, 0, '')
  22. endfunction
  23. func Test_set_linebreak()
  24. call s:test_windows('setl ts=4 sbr=+')
  25. call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
  26. let lines = s:screen_lines([1, 4], winwidth(0))
  27. let expect = [
  28. \ " abcdef ",
  29. \ "+hijklmn ",
  30. \ "+pqrstuvwxyz_1060ABC",
  31. \ "+DEFGHIJKLMNOP ",
  32. \ ]
  33. call s:compare_lines(expect, lines)
  34. call s:close_windows()
  35. endfunc
  36. func Test_linebreak_with_list()
  37. throw 'skipped: Nvim does not support enc=latin1'
  38. set listchars=
  39. call s:test_windows('setl ts=4 sbr=+ list listchars=')
  40. call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
  41. let lines = s:screen_lines([1, 4], winwidth(0))
  42. let expect = [
  43. \ "^Iabcdef hijklmn^I ",
  44. \ "+pqrstuvwxyz_1060ABC",
  45. \ "+DEFGHIJKLMNOP ",
  46. \ "~ ",
  47. \ ]
  48. call s:compare_lines(expect, lines)
  49. call s:close_windows()
  50. set listchars&vim
  51. endfunc
  52. func Test_linebreak_with_nolist()
  53. call s:test_windows('setl ts=4 sbr=+ nolist')
  54. call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
  55. let lines = s:screen_lines([1, 4], winwidth(0))
  56. let expect = [
  57. \ " abcdef ",
  58. \ "+hijklmn ",
  59. \ "+pqrstuvwxyz_1060ABC",
  60. \ "+DEFGHIJKLMNOP ",
  61. \ ]
  62. call s:compare_lines(expect, lines)
  63. call s:close_windows()
  64. endfunc
  65. func Test_linebreak_with_list_and_number()
  66. call s:test_windows('setl list listchars+=tab:>-')
  67. call setline(1, ["abcdefg\thijklmnopqrstu", "v"])
  68. let lines = s:screen_lines([1, 4], winwidth(0))
  69. let expect_nonumber = [
  70. \ "abcdefg>------------",
  71. \ "hijklmnopqrstu$ ",
  72. \ "v$ ",
  73. \ "~ ",
  74. \ ]
  75. call s:compare_lines(expect_nonumber, lines)
  76. setl number
  77. let lines = s:screen_lines([1, 4], winwidth(0))
  78. let expect_number = [
  79. \ " 1 abcdefg>--------",
  80. \ " hijklmnopqrstu$ ",
  81. \ " 2 v$ ",
  82. \ "~ ",
  83. \ ]
  84. call s:compare_lines(expect_number, lines)
  85. call s:close_windows()
  86. endfunc
  87. func Test_should_break()
  88. call s:test_windows('setl sbr=+ nolist')
  89. call setline(1, "1\t" . repeat('a', winwidth(0)-2))
  90. let lines = s:screen_lines([1, 4], winwidth(0))
  91. let expect = [
  92. \ "1 ",
  93. \ "+aaaaaaaaaaaaaaaaaa ",
  94. \ "~ ",
  95. \ "~ ",
  96. \ ]
  97. call s:compare_lines(expect, lines)
  98. call s:close_windows()
  99. endfunc
  100. func Test_linebreak_with_conceal()
  101. call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab')
  102. call setline(1, "_S_\t bla")
  103. syn match ConcealVar contained /_/ conceal
  104. syn match All /.*/ contains=ConcealVar
  105. let lines = s:screen_lines([1, 4], winwidth(0))
  106. let expect = [
  107. \ "Sabbbbbb bla ",
  108. \ "~ ",
  109. \ "~ ",
  110. \ "~ ",
  111. \ ]
  112. call s:compare_lines(expect, lines)
  113. call s:close_windows()
  114. endfunc
  115. func Test_linebreak_with_visual_operations()
  116. call s:test_windows()
  117. let line = '1234567890 2234567890 3234567890'
  118. call setline(1, line)
  119. " yank
  120. exec "norm! ^w\<C-V>ey"
  121. call assert_equal('2234567890', @@)
  122. exec "norm! w\<C-V>ey"
  123. call assert_equal('3234567890', @@)
  124. " increment / decrement
  125. exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>"
  126. call assert_equal('1234567890 3234567890 2234567890', getline(1))
  127. " replace
  128. exec "norm! ^w\<C-V>3lraw\<C-V>3lrb"
  129. call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1))
  130. " tilde
  131. exec "norm! ^w\<C-V>2l~w\<C-V>2l~"
  132. call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1))
  133. " delete and insert
  134. exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>"
  135. call assert_equal('1234567890 2345567890 3456567890', getline(1))
  136. call assert_equal('BBBb', @@)
  137. call s:close_windows()
  138. endfunc
  139. " Test that cursor is drawn at correct position after an operator when
  140. " 'linebreak' is enabled.
  141. func Test_linebreak_reset_restore()
  142. CheckScreendump
  143. " f_wincol() calls validate_cursor()
  144. let lines =<< trim END
  145. set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
  146. call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
  147. END
  148. call writefile(lines, 'XlbrResetRestore', 'D')
  149. let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
  150. call term_sendkeys(buf, '$v$')
  151. call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
  152. call term_sendkeys(buf, 'zo')
  153. call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
  154. call term_sendkeys(buf, '$v$')
  155. call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
  156. call term_sendkeys(buf, 'gq')
  157. call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
  158. call term_sendkeys(buf, "$\<C-V>$")
  159. call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
  160. call term_sendkeys(buf, 'I')
  161. call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
  162. call term_sendkeys(buf, "\<Esc>$v$")
  163. call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
  164. call term_sendkeys(buf, 's')
  165. call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
  166. call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
  167. " clean up
  168. call term_sendkeys(buf, "\<Esc>")
  169. call StopVimInTerminal(buf)
  170. endfunc
  171. func Test_virtual_block()
  172. call s:test_windows('setl sbr=+')
  173. call setline(1, [
  174. \ "REMOVE: this not",
  175. \ "REMOVE: aaaaaaaaaaaaa",
  176. \ ])
  177. exe "norm! 1/^REMOVE:"
  178. exe "norm! 0\<C-V>jf x"
  179. $put
  180. let lines = s:screen_lines([1, 4], winwidth(0))
  181. let expect = [
  182. \ "this not ",
  183. \ "aaaaaaaaaaaaa ",
  184. \ "REMOVE: ",
  185. \ "REMOVE: ",
  186. \ ]
  187. call s:compare_lines(expect, lines)
  188. call s:close_windows()
  189. endfunc
  190. func Test_virtual_block_and_vbA()
  191. call s:test_windows()
  192. call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
  193. exe "norm! $3B\<C-v>eAx\<Esc>"
  194. let lines = s:screen_lines([1, 10], winwidth(0))
  195. let expect = [
  196. \ "<<<bar foobar ",
  197. \ "foobar foobar ",
  198. \ "foobar foobar ",
  199. \ "foobar foobar ",
  200. \ "foobar foobar ",
  201. \ "foobar foobar ",
  202. \ "foobar foobar ",
  203. \ "foobar foobar ",
  204. \ "foobar foobar ",
  205. \ "foobar TARGETx at ",
  206. \ ]
  207. call s:compare_lines(expect, lines)
  208. call s:close_windows()
  209. endfunc
  210. func Test_virtual_char_and_block()
  211. call s:test_windows()
  212. call setline(1, "1111-1111-1111-11-1111-1111-1111")
  213. exe "norm! 0f-lv3lc2222\<Esc>bgj."
  214. let lines = s:screen_lines([1, 2], winwidth(0))
  215. let expect = [
  216. \ "1111-2222-1111-11- ",
  217. \ "1111-2222-1111 ",
  218. \ ]
  219. call s:compare_lines(expect, lines)
  220. call s:close_windows()
  221. endfunc
  222. func Test_undo_after_block_visual()
  223. call s:test_windows()
  224. call setline(1, ["aaa", "aaa", "a"])
  225. exe "norm! gg\<C-V>2j~e."
  226. let lines = s:screen_lines([1, 3], winwidth(0))
  227. let expect = [
  228. \ "AaA ",
  229. \ "AaA ",
  230. \ "A ",
  231. \ ]
  232. call s:compare_lines(expect, lines)
  233. call s:close_windows()
  234. endfunc
  235. func Test_norm_after_block_visual()
  236. call s:test_windows()
  237. call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
  238. exe "norm! ggf{\<C-V>\<C-V>c%"
  239. let lines = s:screen_lines([1, 3], winwidth(0))
  240. let expect = [
  241. \ "abcdpgrs ",
  242. \ "~ ",
  243. \ "~ ",
  244. \ ]
  245. call s:compare_lines(expect, lines)
  246. call s:close_windows()
  247. endfunc
  248. func Test_block_replace_after_wrapping()
  249. throw 'skipped: Nvim does not support enc=latin1'
  250. call s:test_windows()
  251. call setline(1, repeat("a", 150))
  252. exe "norm! 0yypk147|\<C-V>jr0"
  253. call assert_equal(repeat("a", 146) . "0aaa", getline(1))
  254. call assert_equal(repeat("a", 146) . "0aaa", getline(2))
  255. let lines = s:screen_lines([1, 10], winwidth(0))
  256. let expect = [
  257. \ "aaaaaaaaaaaaaaaaaaaa",
  258. \ "aaaaaaaaaaaaaaaaaaaa",
  259. \ "aaaaaaaaaaaaaaaaaaaa",
  260. \ "aaaaaaaaaaaaaaaaaaaa",
  261. \ "aaaaaaaaaaaaaaaaaaaa",
  262. \ "aaaaaaaaaaaaaaaaaaaa",
  263. \ "aaaaaaaaaaaaaaaaaaaa",
  264. \ "aaaaaa0aaa ",
  265. \ "@ ",
  266. \ "@ ",
  267. \ ]
  268. call s:compare_lines(expect, lines)
  269. call s:close_windows()
  270. endfunc
  271. func Test_list_with_listchars()
  272. call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
  273. call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
  274. let lines = s:screen_lines([1, 3], winwidth(0))
  275. let expect = [
  276. \ "a_ ",
  277. \ "aaaaaaaaaaaaaaaaaaaa",
  278. \ "aa>-----a-$ ",
  279. \ ]
  280. call s:compare_lines(expect, lines)
  281. call s:close_windows()
  282. endfunc
  283. func Test_list_with_tab_and_skipping_first_chars()
  284. call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
  285. call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
  286. call cursor(4,64)
  287. norm! 2zl
  288. let lines = s:screen_lines([1, 4], winwidth(0))
  289. let expect = [
  290. \ "---------------aaaaa",
  291. \ "---------------aaaaa",
  292. \ "---------------aaaaa",
  293. \ "iiiiiiiii>-----aaaaa",
  294. \ ]
  295. call s:compare_lines(expect, lines)
  296. call s:close_windows()
  297. endfunc
  298. func Test_ctrl_char_on_wrap_column()
  299. call s:test_windows("setl nolbr wrap sbr=")
  300. call setline(1, 'aaa' .. repeat("\<C-A>", 150) .. 'bbb')
  301. call cursor(1,1)
  302. norm! $
  303. redraw!
  304. let expect=[
  305. \ '<<<^A^A^A^A^A^A^A^A^',
  306. \ 'A^A^A^A^A^A^A^A^A^A^',
  307. \ 'A^A^A^A^A^A^A^A^A^A^',
  308. \ 'A^A^A^A^A^A^A^A^A^A^',
  309. \ 'A^A^A^A^A^A^A^A^A^A^',
  310. \ 'A^A^A^A^A^A^A^A^A^A^',
  311. \ 'A^A^A^A^A^A^A^A^A^A^',
  312. \ 'A^A^A^A^A^A^A^A^A^A^',
  313. \ 'A^A^A^A^A^A^A^A^A^A^',
  314. \ 'A^Abbb ']
  315. let lines = s:screen_lines([1, 10], winwidth(0))
  316. call s:compare_lines(expect, lines)
  317. call assert_equal(len(expect), winline())
  318. call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  319. setl sbr=!!
  320. redraw!
  321. let expect=[
  322. \ '!!A^A^A^A^A^A^A^A^A^',
  323. \ '!!A^A^A^A^A^A^A^A^A^',
  324. \ '!!A^A^A^A^A^A^A^A^A^',
  325. \ '!!A^A^A^A^A^A^A^A^A^',
  326. \ '!!A^A^A^A^A^A^A^A^A^',
  327. \ '!!A^A^A^A^A^A^A^A^A^',
  328. \ '!!A^A^A^A^A^A^A^A^A^',
  329. \ '!!A^A^A^A^A^A^A^A^A^',
  330. \ '!!A^A^A^A^A^A^A^A^A^',
  331. \ '!!A^A^A^A^A^A^Abbb ']
  332. let lines = s:screen_lines([1, 10], winwidth(0))
  333. call s:compare_lines(expect, lines)
  334. call assert_equal(len(expect), winline())
  335. call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
  336. call s:close_windows()
  337. endfunc
  338. func Test_linebreak_no_break_after_whitespace_only()
  339. call s:test_windows('setl ts=4 linebreak wrap')
  340. call setline(1, "\t abcdefghijklmnopqrstuvwxyz" ..
  341. \ "abcdefghijklmnopqrstuvwxyz")
  342. let lines = s:screen_lines([1, 4], winwidth(0))
  343. let expect = [
  344. \ " abcdefghijklmn",
  345. \ "opqrstuvwxyzabcdefgh",
  346. \ "ijklmnopqrstuvwxyz ",
  347. \ "~ ",
  348. \ ]
  349. call s:compare_lines(expect, lines)
  350. call s:close_windows()
  351. endfunc
  352. " vim: shiftwidth=2 sts=2 expandtab