blob: 4a43feab745c9824596d7ff25e1d4820ead43123 [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)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010018 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
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
76func Test_should_break()
77 call s:test_windows('setl sbr=+ nolist')
78 call setline(1, "1\t" . repeat('a', winwidth(0)-2))
79 let lines = s:screen_lines([1, 4], winwidth(0))
80 let expect = [
81\ "1 ",
82\ "+aaaaaaaaaaaaaaaaaa ",
83\ "~ ",
84\ "~ ",
85\ ]
86 call s:compare_lines(expect, lines)
87 call s:close_windows()
88endfunc
89
90func Test_linebreak_with_conceal()
91 call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab')
92 call setline(1, "_S_\t bla")
93 syn match ConcealVar contained /_/ conceal
94 syn match All /.*/ contains=ConcealVar
95 let lines = s:screen_lines([1, 4], winwidth(0))
96 let expect = [
97\ "Sabbbbbb bla ",
98\ "~ ",
99\ "~ ",
100\ "~ ",
101\ ]
102 call s:compare_lines(expect, lines)
103 call s:close_windows()
104endfunc
105
Bram Moolenaar03c3bd92020-01-23 20:58:09 +0100106func Test_linebreak_with_visual_operations()
107 call s:test_windows()
108 let line = '1234567890 2234567890 3234567890'
109 call setline(1, line)
110
111 " yank
112 exec "norm! ^w\<C-V>ey"
113 call assert_equal('2234567890', @@)
114 exec "norm! w\<C-V>ey"
115 call assert_equal('3234567890', @@)
116
117 " increment / decrement
118 exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>"
119 call assert_equal('1234567890 3234567890 2234567890', getline(1))
120
121 " replace
122 exec "norm! ^w\<C-V>3lraw\<C-V>3lrb"
123 call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1))
124
125 " tilde
126 exec "norm! ^w\<C-V>2l~w\<C-V>2l~"
127 call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1))
128
129 " delete and insert
130 exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>"
131 call assert_equal('1234567890 2345567890 3456567890', getline(1))
132 call assert_equal('BBBb', @@)
133
134 call s:close_windows()
135endfunc
136
zeertzjq30c0c462022-10-09 11:44:28 +0100137" Test that cursor is drawn at correct position after an operator when
138" 'linebreak' is enabled.
Bram Moolenaar16dab412022-10-08 16:41:32 +0100139func Test_linebreak_reset_restore()
140 CheckScreendump
141
zeertzjq30c0c462022-10-09 11:44:28 +0100142 " f_wincol() calls validate_cursor()
Bram Moolenaar16dab412022-10-08 16:41:32 +0100143 let lines =<< trim END
zeertzjq30c0c462022-10-09 11:44:28 +0100144 set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
145 call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
Bram Moolenaar16dab412022-10-08 16:41:32 +0100146 END
147 call writefile(lines, 'XlbrResetRestore', 'D')
148 let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
149
zeertzjq30c0c462022-10-09 11:44:28 +0100150 call term_sendkeys(buf, '$v$')
151 call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
152 call term_sendkeys(buf, 'zo')
153 call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
154
155 call term_sendkeys(buf, '$v$')
156 call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
157 call term_sendkeys(buf, 'gq')
158 call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
159
160 call term_sendkeys(buf, "$\<C-V>$")
161 call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
162 call term_sendkeys(buf, 'I')
163 call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
164
165 call term_sendkeys(buf, "\<Esc>$v$")
166 call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
167 call term_sendkeys(buf, 's')
168 call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
Bram Moolenaar16dab412022-10-08 16:41:32 +0100169 call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
170
zeertzjq30c0c462022-10-09 11:44:28 +0100171 " clean up
Bram Moolenaar16dab412022-10-08 16:41:32 +0100172 call term_sendkeys(buf, "\<Esc>")
173 call StopVimInTerminal(buf)
174endfunc
175
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100176func Test_virtual_block()
177 call s:test_windows('setl sbr=+')
178 call setline(1, [
179\ "REMOVE: this not",
180\ "REMOVE: aaaaaaaaaaaaa",
181\ ])
182 exe "norm! 1/^REMOVE:"
183 exe "norm! 0\<C-V>jf x"
184 $put
185 let lines = s:screen_lines([1, 4], winwidth(0))
186 let expect = [
187\ "this not ",
188\ "aaaaaaaaaaaaa ",
189\ "REMOVE: ",
190\ "REMOVE: ",
191\ ]
192 call s:compare_lines(expect, lines)
193 call s:close_windows()
194endfunc
195
196func Test_virtual_block_and_vbA()
197 call s:test_windows()
198 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
199 exe "norm! $3B\<C-v>eAx\<Esc>"
200 let lines = s:screen_lines([1, 10], winwidth(0))
201 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100202\ "<<<bar foobar ",
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100203\ "foobar foobar ",
204\ "foobar foobar ",
205\ "foobar foobar ",
206\ "foobar foobar ",
207\ "foobar foobar ",
208\ "foobar foobar ",
209\ "foobar foobar ",
210\ "foobar foobar ",
211\ "foobar TARGETx at ",
212\ ]
213 call s:compare_lines(expect, lines)
214 call s:close_windows()
215endfunc
216
217func Test_virtual_char_and_block()
218 call s:test_windows()
219 call setline(1, "1111-1111-1111-11-1111-1111-1111")
220 exe "norm! 0f-lv3lc2222\<Esc>bgj."
221 let lines = s:screen_lines([1, 2], winwidth(0))
222 let expect = [
223\ "1111-2222-1111-11- ",
224\ "1111-2222-1111 ",
225\ ]
226 call s:compare_lines(expect, lines)
227 call s:close_windows()
228endfunc
229
230func Test_undo_after_block_visual()
231 call s:test_windows()
232 call setline(1, ["aaa", "aaa", "a"])
233 exe "norm! gg\<C-V>2j~e."
234 let lines = s:screen_lines([1, 3], winwidth(0))
235 let expect = [
236\ "AaA ",
237\ "AaA ",
238\ "A ",
239\ ]
240 call s:compare_lines(expect, lines)
241 call s:close_windows()
242endfunc
243
244func Test_norm_after_block_visual()
245 call s:test_windows()
246 call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
247 exe "norm! ggf{\<C-V>\<C-V>c%"
248 let lines = s:screen_lines([1, 3], winwidth(0))
249 let expect = [
250\ "abcdpgrs ",
251\ "~ ",
252\ "~ ",
253\ ]
254 call s:compare_lines(expect, lines)
255 call s:close_windows()
256endfunc
257
258func Test_block_replace_after_wrapping()
259 call s:test_windows()
260 call setline(1, repeat("a", 150))
261 exe "norm! 0yypk147|\<C-V>jr0"
262 call assert_equal(repeat("a", 146) . "0aaa", getline(1))
263 call assert_equal(repeat("a", 146) . "0aaa", getline(2))
264 let lines = s:screen_lines([1, 10], winwidth(0))
265 let expect = [
266\ "aaaaaaaaaaaaaaaaaaaa",
267\ "aaaaaaaaaaaaaaaaaaaa",
268\ "aaaaaaaaaaaaaaaaaaaa",
269\ "aaaaaaaaaaaaaaaaaaaa",
270\ "aaaaaaaaaaaaaaaaaaaa",
271\ "aaaaaaaaaaaaaaaaaaaa",
272\ "aaaaaaaaaaaaaaaaaaaa",
273\ "aaaaaa0aaa ",
274\ "@ ",
275\ "@ ",
276\ ]
277 call s:compare_lines(expect, lines)
278 call s:close_windows()
279endfunc
280
281func Test_list_with_listchars()
282 call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
283 call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
284 let lines = s:screen_lines([1, 3], winwidth(0))
285 let expect = [
286\ "a_ ",
287\ "aaaaaaaaaaaaaaaaaaaa",
288\ "aa>-----a-$ ",
289\ ]
290 call s:compare_lines(expect, lines)
291 call s:close_windows()
292endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100293
294func Test_list_with_tab_and_skipping_first_chars()
295 call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
296 call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
297 call cursor(4,64)
298 norm! 2zl
299 let lines = s:screen_lines([1, 4], winwidth(0))
300 let expect = [
301\ "---------------aaaaa",
302\ "---------------aaaaa",
303\ "---------------aaaaa",
304\ "iiiiiiiii>-----aaaaa",
305\ ]
306 call s:compare_lines(expect, lines)
307 call s:close_windows()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200308endfunc
309
310" vim: shiftwidth=2 sts=2 expandtab