robin/laufey

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

Justin M. Keyesfeat(input)!: CmdAtom event #4129764a301184e

master
13.9 KiB368 linesraw
1-- Test for linebreak and list option (non-utf8)
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 feed, insert, source = n.feed, n.insert, n.source
9local clear, command, feed_command, expect = n.clear, n.command, n.feed_command, n.expect
10
11describe('listlbr', function()
12  before_each(clear)
13
14  -- luacheck: ignore 621 (Indentation)
15  -- luacheck: ignore 611 (Line contains only whitespaces)
16  -- luacheck: ignore 613 (Trailing whitespaces in a string)
17  it('is working', function()
18    insert([[
19      dummy text]])
20
21    feed_command('set wildchar=^E')
22    feed_command('10new')
23    feed_command('vsp')
24    feed_command('vert resize 20')
25    feed_command([[put =\"\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP \"]])
26    feed_command('norm! zt')
27    feed_command('set ts=4 sw=4 sts=4 linebreak sbr=+ wrap')
28    source([[
29      fu! ScreenChar(width)
30        let c=''
31        for j in range(1,4)
32          for i in range(1,a:width)
33            let c.=nr2char(screenchar(j, i))
34          endfor
35          let c.="\n"
36        endfor
37        return c
38      endfu
39      fu! DoRecordScreen()
40        wincmd l
41        $put =printf(\"\n%s\", g:test)
42        $put =g:line
43        wincmd p
44      endfu
45    ]])
46    feed_command('let g:test="Test 1: set linebreak"')
47    feed_command('redraw!')
48    feed_command('let line=ScreenChar(winwidth(0))')
49    feed_command('call DoRecordScreen()')
50
51    feed_command('let g:test="Test 2: set linebreak + set list"')
52    feed_command('set linebreak list listchars=')
53    feed_command('redraw!')
54    feed_command('let line=ScreenChar(winwidth(0))')
55    feed_command('call DoRecordScreen()')
56
57    feed_command('let g:test ="Test 3: set linebreak nolist"')
58    feed_command('set nolist linebreak')
59    feed_command('redraw!')
60    feed_command('let line=ScreenChar(winwidth(0))')
61    feed_command('call DoRecordScreen()')
62
63    feed_command(
64      'let g:test ="Test 4: set linebreak with tab and 1 line as long as screen: should break!"'
65    )
66    feed_command('set nolist linebreak ts=8')
67    feed_command([[let line="1\t".repeat('a', winwidth(0)-2)]])
68    feed_command('$put =line')
69    feed_command('$')
70    feed_command('norm! zt')
71    feed_command('redraw!')
72    feed_command('let line=ScreenChar(winwidth(0))')
73    feed_command('call DoRecordScreen()')
74    feed_command([[let line="_S_\t bla"]])
75    feed_command('$put =line')
76    feed_command('$')
77    feed_command('norm! zt')
78
79    feed_command(
80      'let g:test ="Test 5: set linebreak with conceal and set list and tab displayed by different char (line may not be truncated)"'
81    )
82    feed_command('set cpo&vim list linebreak conceallevel=2 concealcursor=nv listchars=tab:ab')
83    feed_command('syn match ConcealVar contained /_/ conceal')
84    feed_command('syn match All /.*/ contains=ConcealVar')
85    feed_command('let line=ScreenChar(winwidth(0))')
86    feed_command('call DoRecordScreen()')
87    feed_command('set cpo&vim linebreak')
88
89    feed_command('let g:test ="Test 6: set linebreak with visual block mode"')
90    feed_command('let line="REMOVE: this not"')
91    feed_command('$put =g:test')
92    feed_command('$put =line')
93    feed_command('let line="REMOVE: aaaaaaaaaaaaa"')
94    feed_command('$put =line')
95    feed_command('1/^REMOVE:')
96    feed('0<C-V>jf x')
97    feed_command('$put')
98    feed_command('set cpo&vim linebreak')
99
100    feed_command('let g:test ="Test 7: set linebreak with visual block mode and v_b_A"')
101    feed_command('$put =g:test')
102    feed('Golong line: <esc>40afoobar <esc>aTARGET at end<esc>')
103    feed_command([[exe "norm! $3B\<C-v>eAx\<Esc>"]])
104    feed_command('set cpo&vim linebreak sbr=')
105
106    feed_command('let g:test ="Test 8: set linebreak with visual char mode and changing block"')
107    feed_command('$put =g:test')
108    feed('Go1111-1111-1111-11-1111-1111-1111<esc>0f-lv3lc2222<esc>bgj.')
109
110    feed_command('let g:test ="Test 9: using redo after block visual mode"')
111    feed_command('$put =g:test')
112    feed('Go<CR>')
113    feed('aaa<CR>')
114    feed('aaa<CR>')
115    feed('a<ESC>2k<C-V>2j~e.<CR>')
116
117    feed_command('let g:test ="Test 10: using normal commands after block-visual"')
118    feed_command('$put =g:test')
119    feed_command('set linebreak')
120    feed('Go<cr>')
121    feed('abcd{ef<cr>')
122    feed('ghijklm<cr>')
123    feed('no}pqrs<esc>2k0f{<C-V><C-V>c%<esc>')
124
125    feed_command('let g:test ="Test 11: using block replace mode after wrapping"')
126    feed_command('$put =g:test')
127    feed_command('set linebreak wrap')
128    feed('Go<esc>150aa<esc>yypk147|<C-V>jr0<cr>')
129
130    feed_command('let g:test ="Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$"')
131    feed_command('set list listchars=space:_,trail:-,tab:>-,eol:$')
132    feed_command('$put =g:test')
133    feed_command([[let line="a aaaaaaaaaaaaaaaaaaaaaa\ta "]])
134    feed_command('$put =line')
135    feed_command('$')
136    feed_command('norm! zt')
137    feed_command('redraw!')
138    feed_command('let line=ScreenChar(winwidth(0))')
139    feed_command('call DoRecordScreen()')
140
141    -- Assert buffer contents.
142    expect([[
143
144      	abcdef hijklmn	pqrstuvwxyz_1060ABCDEFGHIJKLMNOP 
145
146      Test 1: set linebreak
147          abcdef          
148      +hijklmn            
149      +pqrstuvwxyz_1060ABC
150      +DEFGHIJKLMNOP      
151
152      Test 2: set linebreak + set list
153      ^Iabcdef hijklmn^I  
154      +pqrstuvwxyz_1060ABC
155      +DEFGHIJKLMNOP      
156                          
157
158      Test 3: set linebreak nolist
159          abcdef          
160      +hijklmn            
161      +pqrstuvwxyz_1060ABC
162      +DEFGHIJKLMNOP      
163      1	aaaaaaaaaaaaaaaaaa
164
165      Test 4: set linebreak with tab and 1 line as long as screen: should break!
166      1                   
167      +aaaaaaaaaaaaaaaaaa 
168      ~                   
169      ~                   
170      _S_	 bla
171
172      Test 5: set linebreak with conceal and set list and tab displayed by different char (line may not be truncated)
173      Sabbbbbb bla        
174      ~                   
175      ~                   
176      ~                   
177      Test 6: set linebreak with visual block mode
178      this not
179      aaaaaaaaaaaaa
180      REMOVE: 
181      REMOVE: 
182      Test 7: set linebreak with visual block mode and v_b_A
183      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 TARGETx at end
184      Test 8: set linebreak with visual char mode and changing block
185      1111-2222-1111-11-1111-2222-1111
186      Test 9: using redo after block visual mode
187
188      AAA
189      AAA
190      A
191      Test 10: using normal commands after block-visual
192
193      abcdpqrs
194      Test 11: using block replace mode after wrapping
195      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0aaa
196      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0aaa
197      Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$
198      a aaaaaaaaaaaaaaaaaaaaaa	a 
199
200      Test 12: set linebreak list listchars=space:_,tab:>-,tail:-,eol:$
201      a_                  
202      aaaaaaaaaaaaaaaaaaaa
203      aa>-----a-$         
204      ~                   ]])
205  end)
206
207  -- oldtest: Test_linebreak_reset_restore()
208  it('cursor position is drawn correctly after operator', function()
209    local screen = Screen.new(60, 6)
210
211    -- f_wincol() calls validate_cursor()
212    source([[
213      set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
214      call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
215    ]])
216
217    feed('$v$')
218    screen:expect([[
219      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
220      bbbbbbbbbb {17:c}^                                                |
221      {1:~                                                           }|*3
222                                                       2          |
223    ]])
224    feed('zo')
225    screen:expect([[
226      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
227      bbbbbbbbbb ^c                                                |
228      {1:~                                                           }|*3
229      {9:E490: No fold found}                                         |
230    ]])
231
232    feed('$v$')
233    screen:expect([[
234      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
235      bbbbbbbbbb {17:c}^                                                |
236      {1:~                                                           }|*3
237      {9:E490: No fold found}                              2          |
238    ]])
239    feed('gq')
240    screen:expect([[
241      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
242      bbbbbbbbbb ^c                                                |
243      {1:~                                                           }|*3
244      {9:E490: No fold found}                                         |
245    ]])
246
247    feed('$<C-V>$')
248    screen:expect([[
249      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
250      bbbbbbbbbb {17:c}^                                                |
251      {1:~                                                           }|*3
252      {9:E490: No fold found}                              1x2        |
253    ]])
254    feed('I')
255    screen:expect([[
256      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
257      bbbbbbbbbb ^c                                                |
258      {1:~                                                           }|*3
259      {9:E490: No fold found}                                         |
260    ]])
261
262    feed('<Esc>$v$')
263    screen:expect([[
264      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
265      bbbbbbbbbb {17:c}^                                                |
266      {1:~                                                           }|*3
267      {9:E490: No fold found}                              2          |
268    ]])
269    feed('s')
270    screen:expect([[
271      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa          |
272      bbbbbbbbbb ^                                                 |
273      {1:~                                                           }|*3
274      {9:E490: No fold found}                                         |
275    ]])
276  end)
277
278  it('does not bleed match/extmark highlight into the filler before a wrapped word', function()
279    local screen = Screen.new(60, 3)
280    screen:add_extra_attr_ids({ [100] = { underline = true } })
281    source([[
282      set wrap linebreak
283      call setline(1, '[license-commit]: https://github.com/neovim/neovim/commit/b17d9691a24099c9210289f16afb1a498a89d803')
284      highlight TestUL gui=underline cterm=underline
285    ]])
286
287    -- Highlight extends past the break point: must not bleed into the filler before the
288    -- pushed-down word, whether applied via matchadd() (search_attr) or an extmark (decor_attr).
289    local expected = [[
290      ^[license-commit]: {100:https://github.com/neovim/neovim/commit/}  |
291      {100:b17d9691a24099c9210289f16afb1a498a89d803}                    |
292                                                                  |
293    ]]
294
295    command([[call matchadd('TestUL', 'https://.*$')]])
296    screen:expect(expected)
297
298    -- Confirm the highlight actually toggles off before re-checking via the extmark path below,
299    -- so the second `expect(expected)` proves that path redraws correctly instead of coasting on
300    -- leftover state from matchadd().
301    command('call clearmatches()')
302    screen:expect([[
303      ^[license-commit]: https://github.com/neovim/neovim/commit/  |
304      b17d9691a24099c9210289f16afb1a498a89d803                    |
305                                                                  |
306    ]])
307
308    command([[call nvim_buf_add_highlight(0, -1, 'TestUL', 0, 18, -1)]])
309    screen:expect(expected)
310  end)
311
312  it('extends a to-end-of-line syntax highlight through the filler', function()
313    local screen = Screen.new(30, 5)
314    screen:add_extra_attr_ids({ [100] = { reverse = true } })
315    source([[
316      set wrap linebreak
317      call setline(1, 'section.heading:' . repeat(' ', 40) . 'END')
318      syntax match TestBar /^.*$/
319      highlight TestBar gui=reverse cterm=reverse
320    ]])
321
322    -- Unlike the tests above: the filler here is real trailing padding covered by the same 'to end
323    -- of line' match, so it must keep the highlight instead of going blank.
324    screen:expect([[
325      {100:^section.                      }|
326      {100:heading:                      }|
327      {100:                  END}         |
328      {1:~                             }|
329                                    |
330    ]])
331  end)
332
333  it('extends a background highlight into the filler only with hl_eol', function()
334    local screen = Screen.new(20, 5)
335    screen:add_extra_attr_ids({ [100] = { background = Screen.colors.Red } })
336    source([[
337      set wrap linebreak
338      call setline(1, 'word1.word2verylongwordthatpushesdown')
339      highlight TestBg guibg=Red ctermbg=Red
340      let g:ns = nvim_create_namespace('')
341    ]])
342
343    -- 'hl_eol' covers cells with no text behind them, so the filler is covered too.
344    command(
345      'call nvim_buf_set_extmark(0, g:ns, 0, 0, '
346        .. "{'end_row': 1, 'hl_group': 'TestBg', 'hl_eol': v:true})"
347    )
348    screen:expect([[
349      {100:^word1.              }|
350      {100:word2verylongwordtha}|
351      {100:tpushesdown         }|
352      {1:~                   }|
353                          |
354    ]])
355
356    -- Without it the highlight decorates characters, so it stops where they do, just as an
357    -- underline already does (see tests above).
358    command('call nvim_buf_clear_namespace(0, -1, 0, -1)')
359    command([[call nvim_buf_add_highlight(0, -1, 'TestBg', 0, 0, -1)]])
360    screen:expect([[
361      {100:^word1.}              |
362      {100:word2verylongwordtha}|
363      {100:tpushesdown}         |
364      {1:~                   }|
365                          |
366    ]])
367  end)
368end)