blob: bcbd886abeadb78d6c9cf05d4837415ffa05a31f [file] [log] [blame]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01001" Test for linebreak and list option (non-utf8)
2
3set encoding=latin1
4scriptencoding latin1
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006source check.vim
7CheckOption linebreak
8CheckFeature conceal
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01009
10source view_util.vim
Bram Moolenaar16dab412022-10-08 16:41:32 +010011source screendump.vim
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010012
13function s:screen_lines(lnum, width) abort
14 return ScreenLines(a:lnum, a:width)
15endfunction
16
Bram Moolenaar1e115362019-01-09 23:01:02 +010017func s:compare_lines(expect, actual)
zeertzjqb557f482023-08-22 22:07:34 +020018 call assert_equal(a:expect, a:actual)
Bram Moolenaar1e115362019-01-09 23:01:02 +010019endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010020
21function s:test_windows(...)
22 call NewWindow(10, 20)
23 setl ts=8 sw=4 sts=4 linebreak sbr= wrap
24 exe get(a:000, 0, '')
25endfunction
26
27function s:close_windows(...)
28 call CloseWindow()
29 exe get(a:000, 0, '')
30endfunction
31
32func Test_set_linebreak()
33 call s:test_windows('setl ts=4 sbr=+')
34 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
35 let lines = s:screen_lines([1, 4], winwidth(0))
36 let expect = [
37\ " abcdef ",
38\ "+hijklmn ",
39\ "+pqrstuvwxyz_1060ABC",
40\ "+DEFGHIJKLMNOP ",
41\ ]
42 call s:compare_lines(expect, lines)
43 call s:close_windows()
44endfunc
45
46func Test_linebreak_with_list()
Bram Moolenaareed9d462021-02-15 20:38:25 +010047 set listchars=
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010048 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()
Bram Moolenaareed9d462021-02-15 20:38:25 +010059 set listchars&vim
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010060endfunc
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
h-east194555c2023-03-02 18:49:09 +000076func 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
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100100func 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
Bram Moolenaar03c3bd92020-01-23 20:58:09 +0100130func 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
zeertzjq30c0c462022-10-09 11:44:28 +0100161" Test that cursor is drawn at correct position after an operator when
162" 'linebreak' is enabled.
Bram Moolenaar16dab412022-10-08 16:41:32 +0100163func Test_linebreak_reset_restore()
164 CheckScreendump
165
zeertzjq30c0c462022-10-09 11:44:28 +0100166 " f_wincol() calls validate_cursor()
Bram Moolenaar16dab412022-10-08 16:41:32 +0100167 let lines =<< trim END
zeertzjq30c0c462022-10-09 11:44:28 +0100168 set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
169 call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
Bram Moolenaar16dab412022-10-08 16:41:32 +0100170 END
171 call writefile(lines, 'XlbrResetRestore', 'D')
172 let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
173
zeertzjq30c0c462022-10-09 11:44:28 +0100174 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])})
Bram Moolenaar16dab412022-10-08 16:41:32 +0100193 call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
194
zeertzjq30c0c462022-10-09 11:44:28 +0100195 " clean up
Bram Moolenaar16dab412022-10-08 16:41:32 +0100196 call term_sendkeys(buf, "\<Esc>")
197 call StopVimInTerminal(buf)
198endfunc
199
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100200func Test_virtual_block()
201 call s:test_windows('setl sbr=+')
202 call setline(1, [
203\ "REMOVE: this not",
204\ "REMOVE: aaaaaaaaaaaaa",
205\ ])
206 exe "norm! 1/^REMOVE:"
207 exe "norm! 0\<C-V>jf x"
208 $put
209 let lines = s:screen_lines([1, 4], winwidth(0))
210 let expect = [
211\ "this not ",
212\ "aaaaaaaaaaaaa ",
213\ "REMOVE: ",
214\ "REMOVE: ",
215\ ]
216 call s:compare_lines(expect, lines)
217 call s:close_windows()
218endfunc
219
220func Test_virtual_block_and_vbA()
221 call s:test_windows()
222 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
223 exe "norm! $3B\<C-v>eAx\<Esc>"
224 let lines = s:screen_lines([1, 10], winwidth(0))
225 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100226\ "<<<bar foobar ",
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100227\ "foobar foobar ",
228\ "foobar foobar ",
229\ "foobar foobar ",
230\ "foobar foobar ",
231\ "foobar foobar ",
232\ "foobar foobar ",
233\ "foobar foobar ",
234\ "foobar foobar ",
235\ "foobar TARGETx at ",
236\ ]
237 call s:compare_lines(expect, lines)
238 call s:close_windows()
239endfunc
240
241func Test_virtual_char_and_block()
242 call s:test_windows()
243 call setline(1, "1111-1111-1111-11-1111-1111-1111")
244 exe "norm! 0f-lv3lc2222\<Esc>bgj."
245 let lines = s:screen_lines([1, 2], winwidth(0))
246 let expect = [
247\ "1111-2222-1111-11- ",
248\ "1111-2222-1111 ",
249\ ]
250 call s:compare_lines(expect, lines)
251 call s:close_windows()
252endfunc
253
254func Test_undo_after_block_visual()
255 call s:test_windows()
256 call setline(1, ["aaa", "aaa", "a"])
257 exe "norm! gg\<C-V>2j~e."
258 let lines = s:screen_lines([1, 3], winwidth(0))
259 let expect = [
260\ "AaA ",
261\ "AaA ",
262\ "A ",
263\ ]
264 call s:compare_lines(expect, lines)
265 call s:close_windows()
266endfunc
267
268func Test_norm_after_block_visual()
269 call s:test_windows()
270 call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
271 exe "norm! ggf{\<C-V>\<C-V>c%"
272 let lines = s:screen_lines([1, 3], winwidth(0))
273 let expect = [
274\ "abcdpgrs ",
275\ "~ ",
276\ "~ ",
277\ ]
278 call s:compare_lines(expect, lines)
279 call s:close_windows()
280endfunc
281
282func Test_block_replace_after_wrapping()
283 call s:test_windows()
284 call setline(1, repeat("a", 150))
285 exe "norm! 0yypk147|\<C-V>jr0"
286 call assert_equal(repeat("a", 146) . "0aaa", getline(1))
287 call assert_equal(repeat("a", 146) . "0aaa", getline(2))
288 let lines = s:screen_lines([1, 10], winwidth(0))
289 let expect = [
290\ "aaaaaaaaaaaaaaaaaaaa",
291\ "aaaaaaaaaaaaaaaaaaaa",
292\ "aaaaaaaaaaaaaaaaaaaa",
293\ "aaaaaaaaaaaaaaaaaaaa",
294\ "aaaaaaaaaaaaaaaaaaaa",
295\ "aaaaaaaaaaaaaaaaaaaa",
296\ "aaaaaaaaaaaaaaaaaaaa",
297\ "aaaaaa0aaa ",
298\ "@ ",
299\ "@ ",
300\ ]
301 call s:compare_lines(expect, lines)
302 call s:close_windows()
303endfunc
304
305func Test_list_with_listchars()
306 call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
307 call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
308 let lines = s:screen_lines([1, 3], winwidth(0))
309 let expect = [
310\ "a_ ",
311\ "aaaaaaaaaaaaaaaaaaaa",
312\ "aa>-----a-$ ",
313\ ]
314 call s:compare_lines(expect, lines)
315 call s:close_windows()
316endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100317
318func Test_list_with_tab_and_skipping_first_chars()
319 call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
320 call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
321 call cursor(4,64)
322 norm! 2zl
323 let lines = s:screen_lines([1, 4], winwidth(0))
324 let expect = [
325\ "---------------aaaaa",
326\ "---------------aaaaa",
327\ "---------------aaaaa",
328\ "iiiiiiiii>-----aaaaa",
329\ ]
330 call s:compare_lines(expect, lines)
331 call s:close_windows()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200332endfunc
333
zeertzjqb557f482023-08-22 22:07:34 +0200334func Test_ctrl_char_on_wrap_column()
335 call s:test_windows("setl nolbr wrap sbr=")
336 call setline(1, 'aaa' .. repeat("\<C-A>", 150) .. 'bbb')
337 call cursor(1,1)
338 norm! $
339 redraw!
340 let expect=[
341\ '<<<^A^A^A^A^A^A^A^A^',
342\ 'A^A^A^A^A^A^A^A^A^A^',
343\ 'A^A^A^A^A^A^A^A^A^A^',
344\ 'A^A^A^A^A^A^A^A^A^A^',
345\ 'A^A^A^A^A^A^A^A^A^A^',
346\ 'A^A^A^A^A^A^A^A^A^A^',
347\ 'A^A^A^A^A^A^A^A^A^A^',
348\ 'A^A^A^A^A^A^A^A^A^A^',
349\ 'A^A^A^A^A^A^A^A^A^A^',
350\ 'A^Abbb ']
351 let lines = s:screen_lines([1, 10], winwidth(0))
352 call s:compare_lines(expect, lines)
353 call assert_equal(len(expect), winline())
354 call assert_equal(strwidth(trim(expect[-1], ' ', 2)), wincol())
355 setl sbr=!!
356 redraw!
357 let expect=[
358\ '!!A^A^A^A^A^A^A^A^A^',
359\ '!!A^A^A^A^A^A^A^A^A^',
360\ '!!A^A^A^A^A^A^A^A^A^',
361\ '!!A^A^A^A^A^A^A^A^A^',
362\ '!!A^A^A^A^A^A^A^A^A^',
363\ '!!A^A^A^A^A^A^A^A^A^',
364\ '!!A^A^A^A^A^A^A^A^A^',
365\ '!!A^A^A^A^A^A^A^A^A^',
366\ '!!A^A^A^A^A^A^A^A^A^',
367\ '!!A^A^A^A^A^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 call s:close_windows()
373endfunc
374
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200375func Test_linebreak_no_break_after_whitespace_only()
376 call s:test_windows('setl ts=4 linebreak wrap')
377 call setline(1, "\tabcdefghijklmnopqrstuvwxyz" ..
378 \ "abcdefghijklmnopqrstuvwxyz")
379 let lines = s:screen_lines([1, 4], winwidth(0))
380 let expect = [
381\ " abcdefghijklmnop",
382\ "qrstuvwxyzabcdefghij",
383\ "klmnopqrstuvwxyz ",
384\ "~ ",
385\ ]
386 call s:compare_lines(expect, lines)
387 call s:close_windows()
388endfunc
389
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200390" vim: shiftwidth=2 sts=2 expandtab