robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

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