robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
11.1 KiB311 linesraw
1-- Test for linebreak and list option in utf-8 mode
2
3local n = require('test.functional.testnvim')()
4local t = require('test.testutil')
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local source = n.source
9local feed = n.feed
10local exec = n.exec
11local clear, expect = n.clear, n.expect
12
13describe('linebreak', function()
14  before_each(clear)
15
16  -- luacheck: ignore 621 (Indentation)
17  -- luacheck: ignore 613 (Trailing whitespaces in a string)
18  it('is working', function()
19    source([[
20      set wildchar=^E
21      10new
22      vsp
23      vert resize 20
24      put =\"\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP \"
25      norm! zt
26      set ts=4 sw=4 sts=4 linebreak sbr=+ wrap
27      fu! ScreenChar(width, lines)
28        let c=''
29        for j in range(1,a:lines)
30            for i in range(1,a:width)
31              let c.=nr2char(screenchar(j, i))
32            endfor
33                 let c.="\n"
34        endfor
35        return c
36      endfu
37      fu! DoRecordScreen()
38        wincmd l
39        $put =printf(\"\n%s\", g:test)
40        $put =g:line
41        wincmd p
42      endfu
43      "
44      let g:test ="Test 1: set linebreak + set list + fancy listchars"
45      exe "set linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6"
46      redraw!
47      let line=ScreenChar(winwidth(0),4)
48      call DoRecordScreen()
49      "
50      let g:test ="Test 2: set nolinebreak list"
51      set list nolinebreak
52      redraw!
53      let line=ScreenChar(winwidth(0),4)
54      call DoRecordScreen()
55      "
56      let g:test ="Test 3: set linebreak nolist"
57      $put =\"\t*mask = nil;\"
58      $
59      norm! zt
60      set nolist linebreak
61      redraw!
62      let line=ScreenChar(winwidth(0),4)
63      call DoRecordScreen()
64      "
65      let g:test ="Test 4: set linebreak list listchars and concealing"
66      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']
67      call append('$', c_defines)
68      vert resize 40
69      $-7
70      norm! zt
71      set list linebreak listchars=tab:>- cole=1
72      syn match Conceal conceal cchar=>'AB\|MSG_MODE'
73      redraw!
74      let line=ScreenChar(winwidth(0),7)
75      call DoRecordScreen()
76      "
77      let g:test ="Test 5: set linebreak list listchars and concealing part2"
78      let c_defines=['bbeeeeee		;	some text']
79      call append('$', c_defines)
80      $
81      norm! zt
82      set nowrap ts=2 list linebreak listchars=tab:>- cole=2 concealcursor=n
83      syn clear
84      syn match meaning    /;\s*\zs.*/
85      syn match hasword    /^\x\{8}/    contains=word
86      syn match word       /\<\x\{8}\>/ contains=beginword,endword contained
87      syn match beginword  /\<\x\x/     contained conceal
88      syn match endword    /\x\{6}\>/   contained
89      hi meaning   guibg=blue
90      hi beginword guibg=green
91      hi endword   guibg=red
92      redraw!
93      let line=ScreenChar(winwidth(0),1)
94      call DoRecordScreen()
95      "
96      let g:test ="Test 6: Screenattributes for comment"
97      $put =g:test
98      call append('$', ' /*		 and some more */')
99      exe "set ft=c ts=7 linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6"
100      syntax on
101      hi SpecialKey term=underline ctermfg=red guifg=red
102      let attr=[]
103      nnoremap <expr> GG ":let attr += ['".screenattr(screenrow(),screencol())."']\n"
104      $
105      norm! zt0
106    ]])
107    feed('GGlGGlGGlGGlGGlGGlGGlGGlGGlGGl')
108    source([[
109      call append('$', ['ScreenAttributes for test6:'])
110      if attr[0] != attr[1] && attr[1] != attr[3] && attr[3] != attr[5]
111         call append('$', "Attribut 0 and 1 and 3 and 5 are different!")
112      else
113         call append('$', "Not all attributes are different")
114      endif
115      set cpo&vim linebreak selection=exclusive
116      let g:test ="Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char"
117      $put =g:test
118    ]])
119    feed("Golong line: <Esc>40afoobar <Esc>aTARGETÃ' at end<Esc>")
120    source([[
121      exe "norm! $3B\<C-v>eAx\<Esc>"
122      "
123      let g:test ="Test 9: a multibyte sign and colorcolumn"
124      let attr=[]
125      let attr2=[]
126      $put =''
127      $put ='a b c'
128      $put ='a b c'
129      set list nolinebreak cc=3
130    ]])
131    feed(':sign define foo text=<C-v>uff0b<CR>')
132    source([[
133      sign place 1 name=foo line=50 buffer=2
134      norm! 2kztj
135      let line1=line('.')
136    ]])
137    feed('0GGlGGlGGlGGl')
138    source([[
139      let line2=line('.')
140      let attr2=attr
141      let attr=[]
142    ]])
143    feed('0GGlGGlGGlGGl')
144    source([[
145      redraw!
146      let line=ScreenChar(winwidth(0),3)
147      call DoRecordScreen()
148      " expected: attr[2] is different because of colorcolumn
149      if attr[0] != attr2[0] || attr[1] != attr2[1] || attr[2] != attr2[2]
150         call append('$', "Screen attributes are different!")
151      else
152         call append('$', "Screen attributes are the same!")
153      endif
154    ]])
155
156    -- Assert buffer contents.
157    expect([[
158
159      	abcdef hijklmn	pqrstuvwxyz 1060ABCDEFGHIJKLMNOP 
160
161      Test 1: set linebreak + set list + fancy listchars
162      ▕———abcdef          
163      +hijklmn▕———        
164      +pqrstuvwxyz␣1060ABC
165      +DEFGHIJKLMNOPˑ¶    
166
167      Test 2: set nolinebreak list
168      ▕———abcdef hijklmn▕—
169      +pqrstuvwxyz␣1060ABC
170      +DEFGHIJKLMNOPˑ¶    
171
172      	*mask = nil;
173
174      Test 3: set linebreak nolist
175          *mask = nil;    
176      ~                   
177      ~                   
178      ~                   
179      #define ABCDE		1
180      #define ABCDEF		1
181      #define ABCDEFG		1
182      #define ABCDEFGH	1
183      #define MSG_MODE_FILE			1
184      #define MSG_MODE_CONSOLE		2
185      #define MSG_MODE_FILE_AND_CONSOLE	3
186      #define MSG_MODE_FILE_THEN_CONSOLE	4
187
188      Test 4: set linebreak list listchars and concealing
189      #define ABCDE>-->---1                   
190      #define >CDEF>-->---1                   
191      #define >CDEFG>->---1                   
192      #define >CDEFGH>----1                   
193      #define >_FILE>--------->--->---1       
194      #define >_CONSOLE>---------->---2       
195      #define >_FILE_AND_CONSOLE>---------3   
196      bbeeeeee		;	some text
197
198      Test 5: set linebreak list listchars and concealing part2
199      eeeeee>--->-;>some text                 
200      Test 6: Screenattributes for comment
201       /*		 and some more */
202      ScreenAttributes for test6:
203      Attribut 0 and 1 and 3 and 5 are different!
204      Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char
205      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
206
207      a b c
208      a b c
209
210      Test 9: a multibyte sign and colorcolumn
211
212      +a b c¶                                
213        a b c¶                                
214      Screen attributes are the same!]])
215  end)
216
217  -- oldtest: Test_visual_ends_before_showbreak()
218  it("Visual area is correct when it ends before multibyte 'showbreak'", function()
219    local screen = Screen.new(60, 6)
220    exec([[
221      let &wrap = v:true
222      let &linebreak = v:true
223      let &showbreak = '↪ '
224      eval ['xxxxx ' .. 'y'->repeat(&columns - 6) .. ' zzzz']->setline(1)
225      normal! wvel
226    ]])
227    screen:expect([[
228      xxxxx                                                       |
229      {1:↪ }{17:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy^    }|
230      {1:↪ }zzzz                                                      |
231      {1:~                                                           }|*2
232      {5:-- VISUAL --}                                                |
233    ]])
234  end)
235
236  it("Visual block highlight is correct with 'linebreak'", function()
237    local screen = Screen.new(60, 6)
238    exec('set laststatus=0 showcmd ruler')
239
240    -- 'linebreak' after end char (initially fixed by patch 7.4.467)
241    exec([[
242      20vnew
243      setlocal linebreak
244      call setline(1, ['foo ' .. repeat('x', 10), 'foo ' .. repeat('x', 20)])
245      exe "normal! gg0\<C-V>3lj"
246    ]])
247    screen:expect([[
248      {17:foo }xxxxxxxxxx      │                                       |
249      {17:foo^ }                │{1:~                                      }|
250      xxxxxxxxxxxxxxxxxxxx│{1:~                                      }|
251      {1:~                   }│{1:~                                      }|*2
252      {5:-- VISUAL BLOCK --}              2x4       2,4            All|
253    ]])
254
255    -- TAB as end char: 'linebreak' shouldn't break Visual block hl
256    exec([[
257      bwipe!
258      setlocal nolinebreak
259      call setline(1, ["foo\tbar", 'foo12345bar', "foo\tbar"])
260      exe "normal! gg03l\<C-V>2j2h"
261    ]])
262    screen:expect([[
263      f{17:oo     }bar                                                 |
264      f{17:oo12345}bar                                                 |
265      f{17:^oo     }bar                                                 |
266      {1:~                                                           }|*2
267      {5:-- VISUAL BLOCK --}              3x7       3,2            All|
268    ]])
269    feed('<Esc>:setlocal linebreak<CR>gv')
270    screen:expect_unchanged(true)
271
272    -- Unprintable end char: 'linebreak' shouldn't break Visual block hl
273    exec([[
274      bwipe!
275      setlocal nolinebreak
276      call setline(1, ["foo\uffffbar", 'foo123456bar', "foo\uffffbar"])
277      exe "normal! gg03l\<C-V>2j2h"
278    ]])
279    screen:expect([[
280      f{17:oo<ffff>}bar                                                |
281      f{17:oo123456}bar                                                |
282      f{17:^oo<ffff>}bar                                                |
283      {1:~                                                           }|*2
284      {5:-- VISUAL BLOCK --}              3x8       3,2            All|
285    ]])
286    feed('<Esc>:setlocal linebreak<CR>gv')
287    screen:expect_unchanged(true)
288
289    -- Virtual text before end char: 'linebreak' shouldn't break Visual block hl
290    exec([=[
291      bwipe!
292      setlocal nolinebreak
293      call setline(1, [repeat('x', 15), repeat('x', 10), repeat('x', 10)])
294      let s:ns = nvim_create_namespace('test')
295      call nvim_buf_set_extmark(0, s:ns, 1, 4, #{virt_text: [['foo: ']],
296                                               \ virt_text_pos: 'inline'})
297      call nvim_buf_set_extmark(0, s:ns, 2, 4, #{virt_text: [['bar: ']],
298                                               \ virt_text_pos: 'inline'})
299      exe "normal! gg02l\<C-V>2j2l"
300    ]=])
301    screen:expect([[
302      xx{17:xxxxxxxx}xxxxx                                             |
303      xx{17:xx}foo: {17:x}xxxxx                                             |
304      xx{17:xx}bar: {17:^x}xxxxx                                             |
305      {1:~                                                           }|*2
306      {5:-- VISUAL BLOCK --}              3x8       3,5-10         All|
307    ]])
308    feed('<Esc>:setlocal linebreak<CR>gv')
309    screen:expect_unchanged(true)
310  end)
311end)