3 " Note: if you get strange failures when adding new tests, it might be that
4 " while the test is run, the breakindent cacheing gets in its way.
5 " It helps to change the tabstop setting and force a redraw (e.g. see
6 " Test_breakindent08())
7 if !exists('+breakindent')
13 let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
15 function s:screen_lines(lnum, width) abort
16 return ScreenLines([a:lnum, a:lnum + 2], a:width)
19 function! s:compare_lines(expect, actual)
20 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
23 function s:test_windows(...)
24 call NewWindow(10, 20)
25 setl ts=4 sw=4 sts=4 breakindent
30 function s:close_windows(...)
35 function Test_breakindent01()
36 " simple breakindent test
37 call s:test_windows('setl briopt=min:0')
38 let lines=s:screen_lines(line('.'),8)
44 call s:compare_lines(expect, lines)
45 call s:close_windows()
48 function Test_breakindent02()
49 " simple breakindent test with showbreak set
50 call s:test_windows('setl briopt=min:0 sbr=>>')
51 let lines=s:screen_lines(line('.'),8)
57 call s:compare_lines(expect, lines)
58 call s:close_windows('set sbr=')
61 function Test_breakindent03()
62 " simple breakindent test with showbreak set and briopt including sbr
63 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
64 let lines=s:screen_lines(line('.'),8)
70 call s:compare_lines(expect, lines)
72 call s:close_windows('set sbr=')
75 function Test_breakindent04()
76 " breakindent set with min width 18
77 call s:test_windows('setl sbr= briopt=min:18')
78 let lines=s:screen_lines(line('.'),8)
84 call s:compare_lines(expect, lines)
86 call s:close_windows('set sbr=')
89 function Test_breakindent05()
90 " breakindent set and shift by 2
91 call s:test_windows('setl briopt=shift:2,min:0')
92 let lines=s:screen_lines(line('.'),8)
98 call s:compare_lines(expect, lines)
99 call s:close_windows()
102 function Test_breakindent06()
103 " breakindent set and shift by -1
104 call s:test_windows('setl briopt=shift:-1,min:0')
105 let lines=s:screen_lines(line('.'),8)
111 call s:compare_lines(expect, lines)
112 call s:close_windows()
115 function Test_breakindent07()
116 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
117 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n')
118 let lines=s:screen_lines(line('.'),10)
124 call s:compare_lines(expect, lines)
126 call s:close_windows('set sbr= cpo-=n')
129 function Test_breakindent07a()
130 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
131 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
132 let lines=s:screen_lines(line('.'),10)
138 call s:compare_lines(expect, lines)
140 call s:close_windows('set sbr=')
143 function Test_breakindent08()
144 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
145 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4')
146 " make sure, cache is invalidated!
151 let lines=s:screen_lines(line('.'),10)
157 call s:compare_lines(expect, lines)
158 call s:close_windows('set sbr= cpo-=n')
161 function Test_breakindent08a()
162 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
163 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
164 let lines=s:screen_lines(line('.'),10)
170 call s:compare_lines(expect, lines)
171 call s:close_windows('set sbr=')
174 function Test_breakindent09()
175 " breakindent set and shift by 1, Number and list set sbr=#
176 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
177 let lines=s:screen_lines(line('.'),10)
183 call s:compare_lines(expect, lines)
184 call s:close_windows('set sbr=')
187 function Test_breakindent10()
188 " breakindent set, Number set sbr=~
189 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
190 " make sure, cache is invalidated!
195 let lines=s:screen_lines(line('.'),10)
201 call s:compare_lines(expect, lines)
202 call s:close_windows('set sbr= cpo-=n')
205 function Test_breakindent11()
206 " test strdisplaywidth()
207 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
209 let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times
210 call assert_equal(width, strdisplaywidth(text))
211 call s:close_windows('set sbr=')
214 function Test_breakindent12()
215 " test breakindent with long indent
216 let s:input="\t\t\t\t\t{"
217 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-')
218 let lines=s:screen_lines(2,16)
220 \ " 2 >--->--->--->",
224 call s:compare_lines(expect, lines)
225 call s:close_windows('set nuw=4 listchars=')
228 function Test_breakindent13()
230 call s:test_windows('setl breakindent briopt=min:10 ts=8')
232 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
237 call assert_equal('d', @a)
238 call assert_equal('w', @b)
239 call s:close_windows()
242 function Test_breakindent14()
244 call s:test_windows('setl breakindent briopt= ts=8')
248 exec "norm! 0\<C-V>tex"
249 let lines=s:screen_lines(line('.'),8)
255 call s:compare_lines(expect, lines)
256 call s:close_windows()
259 function Test_breakindent15()
261 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
264 exe "normal! >>\<C-V>3f0x"
265 let lines=s:screen_lines(line('.'),20)
271 call s:compare_lines(expect, lines)
272 call s:close_windows()
275 function Test_breakindent16()
276 " Check that overlong lines are indented correctly.
278 call s:test_windows('setl breakindent briopt=min:0 ts=4')
279 call setline(1, "\t".repeat("1234567890", 10))
283 let lines=s:screen_lines(1,10)
289 call s:compare_lines(expect, lines)
290 let lines=s:screen_lines(4,10)
296 call s:compare_lines(expect, lines)
297 call s:close_windows()