blob: ace398b18bde67df1ebfb581f12d3a93850be642 [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
Bram Moolenaar16dab412022-10-08 16:41:32 +0100137func Test_linebreak_reset_restore()
138 CheckScreendump
139
140 let lines =<< trim END
141 vim9script
142 &linebreak = true
143 &showcmd = true
144 &showmode = false
145 ('a'->repeat(&columns - 10) .. ' ' .. 'b'->repeat(10) .. ' c')->setline(1)
146 END
147 call writefile(lines, 'XlbrResetRestore', 'D')
148 let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
149
150 call term_sendkeys(buf, '$v$s')
151 call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
152
153 call term_sendkeys(buf, "\<Esc>")
154 call StopVimInTerminal(buf)
155endfunc
156
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100157func Test_virtual_block()
158 call s:test_windows('setl sbr=+')
159 call setline(1, [
160\ "REMOVE: this not",
161\ "REMOVE: aaaaaaaaaaaaa",
162\ ])
163 exe "norm! 1/^REMOVE:"
164 exe "norm! 0\<C-V>jf x"
165 $put
166 let lines = s:screen_lines([1, 4], winwidth(0))
167 let expect = [
168\ "this not ",
169\ "aaaaaaaaaaaaa ",
170\ "REMOVE: ",
171\ "REMOVE: ",
172\ ]
173 call s:compare_lines(expect, lines)
174 call s:close_windows()
175endfunc
176
177func Test_virtual_block_and_vbA()
178 call s:test_windows()
179 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
180 exe "norm! $3B\<C-v>eAx\<Esc>"
181 let lines = s:screen_lines([1, 10], winwidth(0))
182 let expect = [
Bram Moolenaar0466d392022-10-03 17:07:34 +0100183\ "<<<bar foobar ",
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100184\ "foobar foobar ",
185\ "foobar foobar ",
186\ "foobar foobar ",
187\ "foobar foobar ",
188\ "foobar foobar ",
189\ "foobar foobar ",
190\ "foobar foobar ",
191\ "foobar foobar ",
192\ "foobar TARGETx at ",
193\ ]
194 call s:compare_lines(expect, lines)
195 call s:close_windows()
196endfunc
197
198func Test_virtual_char_and_block()
199 call s:test_windows()
200 call setline(1, "1111-1111-1111-11-1111-1111-1111")
201 exe "norm! 0f-lv3lc2222\<Esc>bgj."
202 let lines = s:screen_lines([1, 2], winwidth(0))
203 let expect = [
204\ "1111-2222-1111-11- ",
205\ "1111-2222-1111 ",
206\ ]
207 call s:compare_lines(expect, lines)
208 call s:close_windows()
209endfunc
210
211func Test_undo_after_block_visual()
212 call s:test_windows()
213 call setline(1, ["aaa", "aaa", "a"])
214 exe "norm! gg\<C-V>2j~e."
215 let lines = s:screen_lines([1, 3], winwidth(0))
216 let expect = [
217\ "AaA ",
218\ "AaA ",
219\ "A ",
220\ ]
221 call s:compare_lines(expect, lines)
222 call s:close_windows()
223endfunc
224
225func Test_norm_after_block_visual()
226 call s:test_windows()
227 call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
228 exe "norm! ggf{\<C-V>\<C-V>c%"
229 let lines = s:screen_lines([1, 3], winwidth(0))
230 let expect = [
231\ "abcdpgrs ",
232\ "~ ",
233\ "~ ",
234\ ]
235 call s:compare_lines(expect, lines)
236 call s:close_windows()
237endfunc
238
239func Test_block_replace_after_wrapping()
240 call s:test_windows()
241 call setline(1, repeat("a", 150))
242 exe "norm! 0yypk147|\<C-V>jr0"
243 call assert_equal(repeat("a", 146) . "0aaa", getline(1))
244 call assert_equal(repeat("a", 146) . "0aaa", getline(2))
245 let lines = s:screen_lines([1, 10], winwidth(0))
246 let expect = [
247\ "aaaaaaaaaaaaaaaaaaaa",
248\ "aaaaaaaaaaaaaaaaaaaa",
249\ "aaaaaaaaaaaaaaaaaaaa",
250\ "aaaaaaaaaaaaaaaaaaaa",
251\ "aaaaaaaaaaaaaaaaaaaa",
252\ "aaaaaaaaaaaaaaaaaaaa",
253\ "aaaaaaaaaaaaaaaaaaaa",
254\ "aaaaaa0aaa ",
255\ "@ ",
256\ "@ ",
257\ ]
258 call s:compare_lines(expect, lines)
259 call s:close_windows()
260endfunc
261
262func Test_list_with_listchars()
263 call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
264 call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
265 let lines = s:screen_lines([1, 3], winwidth(0))
266 let expect = [
267\ "a_ ",
268\ "aaaaaaaaaaaaaaaaaaaa",
269\ "aa>-----a-$ ",
270\ ]
271 call s:compare_lines(expect, lines)
272 call s:close_windows()
273endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100274
275func Test_list_with_tab_and_skipping_first_chars()
276 call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
277 call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
278 call cursor(4,64)
279 norm! 2zl
280 let lines = s:screen_lines([1, 4], winwidth(0))
281 let expect = [
282\ "---------------aaaaa",
283\ "---------------aaaaa",
284\ "---------------aaaaa",
285\ "iiiiiiiii>-----aaaaa",
286\ ]
287 call s:compare_lines(expect, lines)
288 call s:close_windows()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200289endfunc
290
291" vim: shiftwidth=2 sts=2 expandtab