listlbr_utf8_spec.lua 7.0 KB

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