blob: bb0f6dd4a959c816fe72fb2dcb6e32370ab0aa32 [file] [log] [blame]
Bram Moolenaar6c896862016-11-17 19:46:51 +01001" Test for breakindent
2"
3" Note: if you get strange failures when adding new tests, it might be that
Bram Moolenaar4b96df52020-01-26 22:00:26 +01004" while the test is run, the breakindent caching gets in its way.
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01005" It helps to change the tabstop setting and force a redraw (e.g. see
Bram Moolenaar6c896862016-11-17 19:46:51 +01006" Test_breakindent08())
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02007source check.vim
8CheckOption breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +01009
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010010source view_util.vim
11
Bram Moolenaar6c896862016-11-17 19:46:51 +010012let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
13
Bram Moolenaar04958cb2018-06-23 19:23:02 +020014func s:screen_lines(lnum, width) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010015 return ScreenLines([a:lnum, a:lnum + 2], a:width)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020016endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010017
Bram Moolenaar04958cb2018-06-23 19:23:02 +020018func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010019 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020020endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010021
Bram Moolenaar04958cb2018-06-23 19:23:02 +020022func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010023 call NewWindow(10, 20)
24 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010025 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010026 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020027endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010028
Bram Moolenaar04958cb2018-06-23 19:23:02 +020029func s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010030 call CloseWindow()
31 exe get(a:000, 0, '')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020032endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010033
Bram Moolenaar04958cb2018-06-23 19:23:02 +020034func Test_breakindent01()
Bram Moolenaar6c896862016-11-17 19:46:51 +010035 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010036 call s:test_windows('setl briopt=min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020037 let lines = s:screen_lines(line('.'),8)
38 let expect = [
39 \ " abcd",
40 \ " qrst",
41 \ " GHIJ",
42 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010043 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010044 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +020045endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010046
Bram Moolenaar04958cb2018-06-23 19:23:02 +020047func Test_breakindent01_vartabs()
48 " like 01 but with vartabs feature
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020049 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020050 call s:test_windows('setl briopt=min:0 vts=4')
51 let lines = s:screen_lines(line('.'),8)
52 let expect = [
53 \ " abcd",
54 \ " qrst",
55 \ " GHIJ",
56 \ ]
57 call s:compare_lines(expect, lines)
58 call s:close_windows('set vts&')
59endfunc
60
61func Test_breakindent02()
Bram Moolenaar6c896862016-11-17 19:46:51 +010062 " simple breakindent test with showbreak set
Bram Moolenaaree857022019-11-09 23:26:40 +010063 set sbr=>>
64 call s:test_windows('setl briopt=min:0 sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020065 let lines = s:screen_lines(line('.'),8)
66 let expect = [
67 \ " abcd",
68 \ " >>qr",
69 \ " >>EF",
70 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010071 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010072 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020073endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +010074
Bram Moolenaar04958cb2018-06-23 19:23:02 +020075func Test_breakindent02_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020076 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +020077 " simple breakindent test with showbreak set
78 call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
79 let lines = s:screen_lines(line('.'),8)
80 let expect = [
81 \ " abcd",
82 \ " >>qr",
83 \ " >>EF",
84 \ ]
85 call s:compare_lines(expect, lines)
86 call s:close_windows('set sbr= vts&')
87endfunc
88
89func Test_breakindent03()
Bram Moolenaar6c896862016-11-17 19:46:51 +010090 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010091 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020092 let lines = s:screen_lines(line('.'),8)
93 let expect = [
94 \ " abcd",
95 \ "++ qrst",
96 \ "++ GHIJ",
97 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010098 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010099 " clean up
100 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200101endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100102
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200103func Test_breakindent03_vartabs()
104 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200105 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200106 call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
107 let lines = s:screen_lines(line('.'),8)
108 let expect = [
109 \ " abcd",
110 \ "++ qrst",
111 \ "++ GHIJ",
112 \ ]
113 call s:compare_lines(expect, lines)
114 " clean up
115 call s:close_windows('set sbr= vts&')
116endfunc
117
118func Test_breakindent04()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100119 " breakindent set with min width 18
Bram Moolenaaree857022019-11-09 23:26:40 +0100120 set sbr=<<<
121 call s:test_windows('setl sbr=NONE briopt=min:18')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200122 let lines = s:screen_lines(line('.'),8)
123 let expect = [
124 \ " abcd",
125 \ " qrstuv",
126 \ " IJKLMN",
127 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100128 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100129 " clean up
130 call s:close_windows('set sbr=')
Bram Moolenaaree857022019-11-09 23:26:40 +0100131 set sbr=
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200132endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100133
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200134func Test_breakindent04_vartabs()
135 " breakindent set with min width 18
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200136 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200137 call s:test_windows('setl sbr= briopt=min:18 vts=4')
138 let lines = s:screen_lines(line('.'),8)
139 let expect = [
140 \ " abcd",
141 \ " qrstuv",
142 \ " IJKLMN",
143 \ ]
144 call s:compare_lines(expect, lines)
145 " clean up
146 call s:close_windows('set sbr= vts&')
147endfunc
148
149func Test_breakindent05()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100150 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100151 call s:test_windows('setl briopt=shift:2,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200152 let lines = s:screen_lines(line('.'),8)
153 let expect = [
154 \ " abcd",
155 \ " qr",
156 \ " EF",
157 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100158 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100159 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200160endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100161
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200162func Test_breakindent05_vartabs()
163 " breakindent set and shift by 2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200164 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200165 call s:test_windows('setl briopt=shift:2,min:0 vts=4')
166 let lines = s:screen_lines(line('.'),8)
167 let expect = [
168 \ " abcd",
169 \ " qr",
170 \ " EF",
171 \ ]
172 call s:compare_lines(expect, lines)
173 call s:close_windows('set vts&')
174endfunc
175
176func Test_breakindent06()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100177 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100178 call s:test_windows('setl briopt=shift:-1,min:0')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200179 let lines = s:screen_lines(line('.'),8)
180 let expect = [
181 \ " abcd",
182 \ " qrstu",
183 \ " HIJKL",
184 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100185 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100186 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200187endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100188
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200189func Test_breakindent06_vartabs()
190 " breakindent set and shift by -1
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200191 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200192 call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
193 let lines = s:screen_lines(line('.'),8)
194 let expect = [
195 \ " abcd",
196 \ " qrstu",
197 \ " HIJKL",
198 \ ]
199 call s:compare_lines(expect, lines)
200 call s:close_windows('set vts&')
201endfunc
202
203func Test_breakindent07()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100204 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100205 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200206 let lines = s:screen_lines(line('.'),10)
207 let expect = [
208 \ " 2 ab",
209 \ "? m",
210 \ "? x",
211 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100212 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100213 " clean up
214 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200215endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100216
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200217func Test_breakindent07_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200218 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200219 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
220 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4')
221 let lines = s:screen_lines(line('.'),10)
222 let expect = [
223 \ " 2 ab",
224 \ "? m",
225 \ "? x",
226 \ ]
227 call s:compare_lines(expect, lines)
228 " clean up
229 call s:close_windows('set sbr= cpo-=n vts&')
230endfunc
231
232func Test_breakindent07a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100233 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100234 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200235 let lines = s:screen_lines(line('.'),10)
236 let expect = [
237 \ " 2 ab",
238 \ " ? m",
239 \ " ? x",
240 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100241 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100242 " clean up
243 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200244endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100245
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200246func Test_breakindent07a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200247 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200248 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
249 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4')
250 let lines = s:screen_lines(line('.'),10)
251 let expect = [
252 \ " 2 ab",
253 \ " ? m",
254 \ " ? x",
255 \ ]
256 call s:compare_lines(expect, lines)
257 " clean up
258 call s:close_windows('set sbr= vts&')
259endfunc
260
261func Test_breakindent08()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100262 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100263 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100264 " make sure, cache is invalidated!
265 set ts=8
266 redraw!
267 set ts=4
268 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200269 let lines = s:screen_lines(line('.'),10)
270 let expect = [
271 \ " 2 ^Iabcd",
272 \ "# opq",
273 \ "# BCD",
274 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100275 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100276 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200277endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100278
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200279func Test_breakindent08_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200280 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200281 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
282 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4')
283 " make sure, cache is invalidated!
284 set ts=8
285 redraw!
286 set ts=4
287 redraw!
288 let lines = s:screen_lines(line('.'),10)
289 let expect = [
290 \ " 2 ^Iabcd",
291 \ "# opq",
292 \ "# BCD",
293 \ ]
294 call s:compare_lines(expect, lines)
295 call s:close_windows('set sbr= cpo-=n vts&')
296endfunc
297
298func Test_breakindent08a()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100299 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100300 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200301 let lines = s:screen_lines(line('.'),10)
302 let expect = [
303 \ " 2 ^Iabcd",
304 \ " # opq",
305 \ " # BCD",
306 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100307 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100308 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200309endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100310
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200311func Test_breakindent08a_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200312 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200313 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
314 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4')
315 let lines = s:screen_lines(line('.'),10)
316 let expect = [
317 \ " 2 ^Iabcd",
318 \ " # opq",
319 \ " # BCD",
320 \ ]
321 call s:compare_lines(expect, lines)
322 call s:close_windows('set sbr= vts&')
323endfunc
324
325func Test_breakindent09()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100326 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100327 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200328 let lines = s:screen_lines(line('.'),10)
329 let expect = [
330 \ " 2 ^Iabcd",
331 \ " #op",
332 \ " #AB",
333 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100334 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100335 call s:close_windows('set sbr=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200336endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100337
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200338func Test_breakindent09_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200339 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200340 " breakindent set and shift by 1, Number and list set sbr=#
341 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4')
342 let lines = s:screen_lines(line('.'),10)
343 let expect = [
344 \ " 2 ^Iabcd",
345 \ " #op",
346 \ " #AB",
347 \ ]
348 call s:compare_lines(expect, lines)
349 call s:close_windows('set sbr= vts&')
350endfunc
351
352func Test_breakindent10()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100353 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100354 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100355 " make sure, cache is invalidated!
356 set ts=8
357 redraw!
358 set ts=4
359 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200360 let lines = s:screen_lines(line('.'),10)
361 let expect = [
362 \ " 2 ab",
363 \ "~ mn",
364 \ "~ yz",
365 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100366 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100367 call s:close_windows('set sbr= cpo-=n')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200368endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100369
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200370func Test_breakindent10_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200371 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200372 " breakindent set, Number set sbr=~
373 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4')
374 " make sure, cache is invalidated!
375 set ts=8
376 redraw!
377 set ts=4
378 redraw!
379 let lines = s:screen_lines(line('.'),10)
380 let expect = [
381 \ " 2 ab",
382 \ "~ mn",
383 \ "~ yz",
384 \ ]
385 call s:compare_lines(expect, lines)
386 call s:close_windows('set sbr= cpo-=n vts&')
387endfunc
388
389func Test_breakindent11()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100390 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100391 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200392 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200393 let width = strlen(text[1:]) + indent(2) + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaar6c896862016-11-17 19:46:51 +0100394 call assert_equal(width, strdisplaywidth(text))
395 call s:close_windows('set sbr=')
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100396 call assert_equal(4, strdisplaywidth("\t", 4))
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200397endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100398
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200399func Test_breakindent11_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200400 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200401 " test strdisplaywidth()
402 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4')
403 let text = getline(2)
Bram Moolenaarf9f24ce2019-08-31 21:17:39 +0200404 let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +0200405 call assert_equal(width, text->strdisplaywidth())
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200406 call s:close_windows('set sbr= vts&')
407endfunc
408
409func Test_breakindent12()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100410 " test breakindent with long indent
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200411 let s:input = "\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100412 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200413 let lines = s:screen_lines(2,16)
414 let expect = [
415 \ " 2 >--->--->--->",
416 \ " ---{ ",
417 \ "~ ",
418 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100419 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100420 call s:close_windows('set nuw=4 listchars=')
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200421endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100422
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200423func Test_breakindent12_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200424 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200425 " test breakindent with long indent
426 let s:input = "\t\t\t\t\t{"
427 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4')
428 let lines = s:screen_lines(2,16)
429 let expect = [
430 \ " 2 >--->--->--->",
431 \ " ---{ ",
432 \ "~ ",
433 \ ]
434 call s:compare_lines(expect, lines)
435 call s:close_windows('set nuw=4 listchars= vts&')
436endfunc
437
438func Test_breakindent13()
439 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100440 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100441 vert resize 20
442 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
443 1
444 norm! fbgj"ayl
445 2
446 norm! fygj"byl
447 call assert_equal('d', @a)
448 call assert_equal('w', @b)
449 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200450endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100451
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200452func Test_breakindent13_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200453 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200454 let s:input = ""
455 call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8')
456 vert resize 20
457 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
458 1
459 norm! fbgj"ayl
460 2
461 norm! fygj"byl
462 call assert_equal('d', @a)
463 call assert_equal('w', @b)
464 call s:close_windows('set vts&')
465endfunc
466
467func Test_breakindent14()
468 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100469 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100470 vert resize 30
471 norm! 3a1234567890
472 norm! a abcde
473 exec "norm! 0\<C-V>tex"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200474 let lines = s:screen_lines(line('.'),8)
475 let expect = [
476 \ "e ",
477 \ "~ ",
478 \ "~ ",
479 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100480 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100481 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200482endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100483
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200484func Test_breakindent14_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200485 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200486 let s:input = ""
487 call s:test_windows('setl breakindent briopt= ts=8 vts=8')
488 vert resize 30
489 norm! 3a1234567890
490 norm! a abcde
491 exec "norm! 0\<C-V>tex"
492 let lines = s:screen_lines(line('.'),8)
493 let expect = [
494 \ "e ",
495 \ "~ ",
496 \ "~ ",
497 \ ]
498 call s:compare_lines(expect, lines)
499 call s:close_windows('set vts&')
500endfunc
501
502func Test_breakindent15()
503 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100504 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100505 vert resize 30
506 norm! 4a1234567890
507 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200508 let lines = s:screen_lines(line('.'),20)
509 let expect = [
510 \ " 1234567890 ",
511 \ "~ ",
512 \ "~ ",
513 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100514 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100515 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200516endfunc
Bram Moolenaar6c896862016-11-17 19:46:51 +0100517
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200518func Test_breakindent15_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200519 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200520 let s:input = ""
521 call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8')
522 vert resize 30
523 norm! 4a1234567890
524 exe "normal! >>\<C-V>3f0x"
525 let lines = s:screen_lines(line('.'),20)
526 let expect = [
527 \ " 1234567890 ",
528 \ "~ ",
529 \ "~ ",
530 \ ]
531 call s:compare_lines(expect, lines)
532 call s:close_windows('set vts&')
533endfunc
534
535func Test_breakindent16()
Bram Moolenaar6c896862016-11-17 19:46:51 +0100536 " Check that overlong lines are indented correctly.
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200537 let s:input = ""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100538 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100539 call setline(1, "\t".repeat("1234567890", 10))
540 resize 6
541 norm! 1gg$
542 redraw!
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200543 let lines = s:screen_lines(1,10)
544 let expect = [
545 \ " 789012",
546 \ " 345678",
547 \ " 901234",
548 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100549 call s:compare_lines(expect, lines)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200550 let lines = s:screen_lines(4,10)
551 let expect = [
552 \ " 567890",
553 \ " 123456",
554 \ " 7890 ",
555 \ ]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100556 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100557 call s:close_windows()
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200558endfunc
559
560func Test_breakindent16_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200561 CheckFeature vartabs
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200562 " Check that overlong lines are indented correctly.
563 let s:input = ""
564 call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4')
565 call setline(1, "\t".repeat("1234567890", 10))
566 resize 6
567 norm! 1gg$
568 redraw!
569 let lines = s:screen_lines(1,10)
570 let expect = [
571 \ " 789012",
572 \ " 345678",
573 \ " 901234",
574 \ ]
575 call s:compare_lines(expect, lines)
576 let lines = s:screen_lines(4,10)
577 let expect = [
578 \ " 567890",
579 \ " 123456",
580 \ " 7890 ",
581 \ ]
582 call s:compare_lines(expect, lines)
583 call s:close_windows('set vts&')
584endfunc
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100585
586func Test_breakindent17_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200587 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100588 let s:input = ""
589 call s:test_windows('setl breakindent list listchars=tab:<-> showbreak=+++')
590 call setline(1, "\t" . repeat('a', 63))
591 vert resize 30
592 norm! 1gg$
593 redraw!
594 let lines = s:screen_lines(1, 30)
595 let expect = [
596 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
597 \ " +++aaaaaaaaaaaaaaaaaaaaaaa",
598 \ " +++aaaaaaaaaaaaaa ",
599 \ ]
600 call s:compare_lines(expect, lines)
601 call s:close_windows('set breakindent& list& listchars& showbreak&')
602endfunc
603
604func Test_breakindent18_vartabs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200605 CheckFeature vartabs
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +0100606 let s:input = ""
607 call s:test_windows('setl breakindent list listchars=tab:<->')
608 call setline(1, "\t" . repeat('a', 63))
609 vert resize 30
610 norm! 1gg$
611 redraw!
612 let lines = s:screen_lines(1, 30)
613 let expect = [
614 \ "<-->aaaaaaaaaaaaaaaaaaaaaaaaaa",
615 \ " aaaaaaaaaaaaaaaaaaaaaaaaaa",
616 \ " aaaaaaaaaaa ",
617 \ ]
618 call s:compare_lines(expect, lines)
619 call s:close_windows('set breakindent& list& listchars&')
620endfunc
621
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100622func Test_breakindent19_sbr_nextpage()
623 let s:input = ""
624 call s:test_windows('setl breakindent briopt=shift:2,sbr,min:18 sbr=>')
625 call setline(1, repeat('a', 200))
626 norm! 1gg
627 redraw!
628 let lines = s:screen_lines(1, 20)
629 let expect = [
630 \ "aaaaaaaaaaaaaaaaaaaa",
631 \ "> aaaaaaaaaaaaaaaaaa",
632 \ "> aaaaaaaaaaaaaaaaaa",
633 \ ]
634 call s:compare_lines(expect, lines)
635 " Scroll down one screen line
636 setl scrolloff=5
Bram Moolenaar52029292021-02-10 21:20:30 +0100637 norm! 5gj
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100638 let lines = s:screen_lines(1, 20)
639 let expect = [
Bram Moolenaar52029292021-02-10 21:20:30 +0100640 \ "aaaaaaaaaaaaaaaaaaaa",
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100641 \ "> aaaaaaaaaaaaaaaaaa",
642 \ "> aaaaaaaaaaaaaaaaaa",
643 \ ]
644 call s:compare_lines(expect, lines)
Bram Moolenaar52029292021-02-10 21:20:30 +0100645 redraw!
646 " moving the cursor doesn't change the text offset
647 norm! l
648 redraw!
649 let lines = s:screen_lines(1, 20)
650 call s:compare_lines(expect, lines)
Bram Moolenaar1aa76b82020-02-23 15:17:27 +0100651
652 setl breakindent briopt=min:18 sbr=>
653 norm! 5gj
654 let lines = s:screen_lines(1, 20)
655 let expect = [
656 \ ">aaaaaaaaaaaaaaaaaaa",
657 \ ">aaaaaaaaaaaaaaaaaaa",
658 \ ">aaaaaaaaaaaaaaaaaaa",
659 \ ]
660 call s:compare_lines(expect, lines)
Bram Moolenaardfede9a2020-01-23 19:59:22 +0100661 call s:close_windows('set breakindent& briopt& sbr&')
662endfunc
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100663
Bram Moolenaare882f7a2020-05-16 14:07:39 +0200664func Test_breakindent20_cpo_n_nextpage()
665 let s:input = ""
666 call s:test_windows('setl breakindent briopt=min:14 cpo+=n number')
667 call setline(1, repeat('a', 200))
668 norm! 1gg
669 redraw!
670 let lines = s:screen_lines(1, 20)
671 let expect = [
672 \ " 1 aaaaaaaaaaaaaaaa",
673 \ " aaaaaaaaaaaaaaaa",
674 \ " aaaaaaaaaaaaaaaa",
675 \ ]
676 call s:compare_lines(expect, lines)
677 " Scroll down one screen line
678 setl scrolloff=5
679 norm! 5gj
680 redraw!
681 let lines = s:screen_lines(1, 20)
682 let expect = [
683 \ "--1 aaaaaaaaaaaaaaaa",
684 \ " aaaaaaaaaaaaaaaa",
685 \ " aaaaaaaaaaaaaaaa",
686 \ ]
687 call s:compare_lines(expect, lines)
688
689 setl briopt+=shift:2
690 norm! 1gg
691 let lines = s:screen_lines(1, 20)
692 let expect = [
693 \ " 1 aaaaaaaaaaaaaaaa",
694 \ " aaaaaaaaaaaaaa",
695 \ " aaaaaaaaaaaaaa",
696 \ ]
697 call s:compare_lines(expect, lines)
698 " Scroll down one screen line
699 norm! 5gj
700 let lines = s:screen_lines(1, 20)
701 let expect = [
702 \ "--1 aaaaaaaaaaaaaa",
703 \ " aaaaaaaaaaaaaa",
704 \ " aaaaaaaaaaaaaa",
705 \ ]
706 call s:compare_lines(expect, lines)
707
708 call s:close_windows('set breakindent& briopt& cpo& number&')
709endfunc
710
Bram Moolenaar0e05de42020-03-25 22:23:46 +0100711" vim: shiftwidth=2 sts=2 expandtab