listlbr_utf8_spec.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. -- Test for linebreak and list option in utf-8 mode
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local source = n.source
  5. local feed = n.feed
  6. local exec = n.exec
  7. local clear, expect = n.clear, n.expect
  8. describe('linebreak', function()
  9. before_each(clear)
  10. -- luacheck: ignore 621 (Indentation)
  11. -- luacheck: ignore 613 (Trailing whitespaces in a string)
  12. it('is working', function()
  13. source([[
  14. set wildchar=^E
  15. 10new
  16. vsp
  17. vert resize 20
  18. put =\"\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP \"
  19. norm! zt
  20. set ts=4 sw=4 sts=4 linebreak sbr=+ wrap
  21. fu! ScreenChar(width, lines)
  22. let c=''
  23. for j in range(1,a:lines)
  24. for i in range(1,a:width)
  25. let c.=nr2char(screenchar(j, i))
  26. endfor
  27. let c.="\n"
  28. endfor
  29. return c
  30. endfu
  31. fu! DoRecordScreen()
  32. wincmd l
  33. $put =printf(\"\n%s\", g:test)
  34. $put =g:line
  35. wincmd p
  36. endfu
  37. "
  38. let g:test ="Test 1: set linebreak + set list + fancy listchars"
  39. exe "set linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6"
  40. redraw!
  41. let line=ScreenChar(winwidth(0),4)
  42. call DoRecordScreen()
  43. "
  44. let g:test ="Test 2: set nolinebreak list"
  45. set list nolinebreak
  46. redraw!
  47. let line=ScreenChar(winwidth(0),4)
  48. call DoRecordScreen()
  49. "
  50. let g:test ="Test 3: set linebreak nolist"
  51. $put =\"\t*mask = nil;\"
  52. $
  53. norm! zt
  54. set nolist linebreak
  55. redraw!
  56. let line=ScreenChar(winwidth(0),4)
  57. call DoRecordScreen()
  58. "
  59. let g:test ="Test 4: set linebreak list listchars and concealing"
  60. let c_defines=['#define ABCDE 1','#define ABCDEF 1','#define ABCDEFG 1','#define ABCDEFGH 1', '#define MSG_MODE_FILE 1','#define MSG_MODE_CONSOLE 2','#define MSG_MODE_FILE_AND_CONSOLE 3','#define MSG_MODE_FILE_THEN_CONSOLE 4']
  61. call append('$', c_defines)
  62. vert resize 40
  63. $-7
  64. norm! zt
  65. set list linebreak listchars=tab:>- cole=1
  66. syn match Conceal conceal cchar=>'AB\|MSG_MODE'
  67. redraw!
  68. let line=ScreenChar(winwidth(0),7)
  69. call DoRecordScreen()
  70. "
  71. let g:test ="Test 5: set linebreak list listchars and concealing part2"
  72. let c_defines=['bbeeeeee ; some text']
  73. call append('$', c_defines)
  74. $
  75. norm! zt
  76. set nowrap ts=2 list linebreak listchars=tab:>- cole=2 concealcursor=n
  77. syn clear
  78. syn match meaning /;\s*\zs.*/
  79. syn match hasword /^\x\{8}/ contains=word
  80. syn match word /\<\x\{8}\>/ contains=beginword,endword contained
  81. syn match beginword /\<\x\x/ contained conceal
  82. syn match endword /\x\{6}\>/ contained
  83. hi meaning guibg=blue
  84. hi beginword guibg=green
  85. hi endword guibg=red
  86. redraw!
  87. let line=ScreenChar(winwidth(0),1)
  88. call DoRecordScreen()
  89. "
  90. let g:test ="Test 6: Screenattributes for comment"
  91. $put =g:test
  92. call append('$', ' /* and some more */')
  93. exe "set ft=c ts=7 linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6"
  94. syntax on
  95. hi SpecialKey term=underline ctermfg=red guifg=red
  96. let attr=[]
  97. nnoremap <expr> GG ":let attr += ['".screenattr(screenrow(),screencol())."']\n"
  98. $
  99. norm! zt0
  100. ]])
  101. feed('GGlGGlGGlGGlGGlGGlGGlGGlGGlGGl')
  102. source([[
  103. call append('$', ['ScreenAttributes for test6:'])
  104. if attr[0] != attr[1] && attr[1] != attr[3] && attr[3] != attr[5]
  105. call append('$', "Attribut 0 and 1 and 3 and 5 are different!")
  106. else
  107. call append('$', "Not all attributes are different")
  108. endif
  109. set cpo&vim linebreak selection=exclusive
  110. let g:test ="Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char"
  111. $put =g:test
  112. ]])
  113. feed("Golong line: <Esc>40afoobar <Esc>aTARGETÃ' at end<Esc>")
  114. source([[
  115. exe "norm! $3B\<C-v>eAx\<Esc>"
  116. "
  117. let g:test ="Test 9: a multibyte sign and colorcolumn"
  118. let attr=[]
  119. let attr2=[]
  120. $put =''
  121. $put ='a b c'
  122. $put ='a b c'
  123. set list nolinebreak cc=3
  124. ]])
  125. feed(':sign define foo text=<C-v>uff0b<CR>')
  126. source([[
  127. sign place 1 name=foo line=50 buffer=2
  128. norm! 2kztj
  129. let line1=line('.')
  130. ]])
  131. feed('0GGlGGlGGlGGl')
  132. source([[
  133. let line2=line('.')
  134. let attr2=attr
  135. let attr=[]
  136. ]])
  137. feed('0GGlGGlGGlGGl')
  138. source([[
  139. redraw!
  140. let line=ScreenChar(winwidth(0),3)
  141. call DoRecordScreen()
  142. " expected: attr[2] is different because of colorcolumn
  143. if attr[0] != attr2[0] || attr[1] != attr2[1] || attr[2] != attr2[2]
  144. call append('$', "Screen attributes are different!")
  145. else
  146. call append('$', "Screen attributes are the same!")
  147. endif
  148. ]])
  149. -- Assert buffer contents.
  150. expect([[
  151. abcdef hijklmn pqrstuvwxyz 1060ABCDEFGHIJKLMNOP
  152. Test 1: set linebreak + set list + fancy listchars
  153. ▕———abcdef
  154. +hijklmn▕———
  155. +pqrstuvwxyz␣1060ABC
  156. +DEFGHIJKLMNOPˑ¶
  157. Test 2: set nolinebreak list
  158. ▕———abcdef hijklmn▕—
  159. +pqrstuvwxyz␣1060ABC
  160. +DEFGHIJKLMNOPˑ¶
  161. *mask = nil;
  162. Test 3: set linebreak nolist
  163. *mask = nil;
  164. ~
  165. ~
  166. ~
  167. #define ABCDE 1
  168. #define ABCDEF 1
  169. #define ABCDEFG 1
  170. #define ABCDEFGH 1
  171. #define MSG_MODE_FILE 1
  172. #define MSG_MODE_CONSOLE 2
  173. #define MSG_MODE_FILE_AND_CONSOLE 3
  174. #define MSG_MODE_FILE_THEN_CONSOLE 4
  175. Test 4: set linebreak list listchars and concealing
  176. #define ABCDE>-->---1
  177. #define >CDEF>-->---1
  178. #define >CDEFG>->---1
  179. #define >CDEFGH>----1
  180. #define >_FILE>--------->--->---1
  181. #define >_CONSOLE>---------->---2
  182. #define >_FILE_AND_CONSOLE>---------3
  183. bbeeeeee ; some text
  184. Test 5: set linebreak list listchars and concealing part2
  185. eeeeee>--->-;>some text
  186. Test 6: Screenattributes for comment
  187. /* and some more */
  188. ScreenAttributes for test6:
  189. Attribut 0 and 1 and 3 and 5 are different!
  190. Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char
  191. long line: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar TARGETÃx' at end
  192. a b c
  193. a b c
  194. Test 9: a multibyte sign and colorcolumn
  195. +a b c¶
  196. a b c¶
  197. Screen attributes are the same!]])
  198. end)
  199. -- oldtest: Test_visual_ends_before_showbreak()
  200. it("Visual area is correct when it ends before multibyte 'showbreak'", function()
  201. local screen = Screen.new(60, 8)
  202. exec([[
  203. let &wrap = v:true
  204. let &linebreak = v:true
  205. let &showbreak = '↪ '
  206. eval ['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1)
  207. normal! wvel
  208. ]])
  209. screen:expect([[
  210. xxxxx |
  211. {1:↪ }{17:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy}^ {17: }|
  212. {1:↪ }zzzz |
  213. {1:~ }|*4
  214. {5:-- VISUAL --} |
  215. ]])
  216. end)
  217. end)