blob: 7deffbe452397913fc0f95a2f9e56bf0cb3ea479 [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
4" while the test is run, the breakindent cacheing 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())
7if !exists('+breakindent')
8 finish
9endif
10
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010011source view_util.vim
12
Bram Moolenaar6c896862016-11-17 19:46:51 +010013let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
14
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010015function s:screen_lines(lnum, width) abort
16 return ScreenLines([a:lnum, a:lnum + 2], a:width)
Bram Moolenaar6c896862016-11-17 19:46:51 +010017endfunction
18
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010019function! s:compare_lines(expect, actual)
20 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
21endfunction
22
23function s:test_windows(...)
24 call NewWindow(10, 20)
25 setl ts=4 sw=4 sts=4 breakindent
Bram Moolenaar6c896862016-11-17 19:46:51 +010026 put =s:input
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010027 exe get(a:000, 0, '')
Bram Moolenaar6c896862016-11-17 19:46:51 +010028endfunction
29
30function s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010031 call CloseWindow()
32 exe get(a:000, 0, '')
Bram Moolenaar6c896862016-11-17 19:46:51 +010033endfunction
34
35function Test_breakindent01()
36 " simple breakindent test
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010037 call s:test_windows('setl briopt=min:0')
38 let lines=s:screen_lines(line('.'),8)
39 let expect=[
40\ " abcd",
41\ " qrst",
42\ " GHIJ",
43\ ]
44 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010045 call s:close_windows()
46endfunction
47
48function Test_breakindent02()
49 " simple breakindent test with showbreak set
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010050 call s:test_windows('setl briopt=min:0 sbr=>>')
51 let lines=s:screen_lines(line('.'),8)
52 let expect=[
53\ " abcd",
54\ " >>qr",
55\ " >>EF",
56\ ]
57 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010058 call s:close_windows('set sbr=')
59endfunction
60
61function Test_breakindent03()
62 " simple breakindent test with showbreak set and briopt including sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010063 call s:test_windows('setl briopt=sbr,min:0 sbr=++')
64 let lines=s:screen_lines(line('.'),8)
65 let expect=[
66\ " abcd",
67\ "++ qrst",
68\ "++ GHIJ",
69\ ]
70 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010071 " clean up
72 call s:close_windows('set sbr=')
73endfunction
74
75function Test_breakindent04()
76 " breakindent set with min width 18
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010077 call s:test_windows('setl sbr= briopt=min:18')
78 let lines=s:screen_lines(line('.'),8)
79 let expect=[
80\ " abcd",
81\ " qrstuv",
82\ " IJKLMN",
83\ ]
84 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010085 " clean up
86 call s:close_windows('set sbr=')
87endfunction
88
89function Test_breakindent05()
90 " breakindent set and shift by 2
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010091 call s:test_windows('setl briopt=shift:2,min:0')
92 let lines=s:screen_lines(line('.'),8)
93 let expect=[
94\ " abcd",
95\ " qr",
96\ " EF",
97\ ]
98 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +010099 call s:close_windows()
100endfunction
101
102function Test_breakindent06()
103 " breakindent set and shift by -1
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100104 call s:test_windows('setl briopt=shift:-1,min:0')
105 let lines=s:screen_lines(line('.'),8)
106 let expect=[
107\ " abcd",
108\ " qrstu",
109\ " HIJKL",
110\ ]
111 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100112 call s:close_windows()
113endfunction
114
115function Test_breakindent07()
116 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100117 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)
119 let expect=[
120\ " 2 ab",
121\ "? m",
122\ "? x",
123\ ]
124 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100125 " clean up
126 call s:close_windows('set sbr= cpo-=n')
127endfunction
128
129function Test_breakindent07a()
130 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100131 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4')
132 let lines=s:screen_lines(line('.'),10)
133 let expect=[
134\ " 2 ab",
135\ " ? m",
136\ " ? x",
137\ ]
138 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100139 " clean up
140 call s:close_windows('set sbr=')
141endfunction
142
143function Test_breakindent08()
144 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100145 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 +0100146 " make sure, cache is invalidated!
147 set ts=8
148 redraw!
149 set ts=4
150 redraw!
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100151 let lines=s:screen_lines(line('.'),10)
152 let expect=[
153\ " 2 ^Iabcd",
154\ "# opq",
155\ "# BCD",
156\ ]
157 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100158 call s:close_windows('set sbr= cpo-=n')
159endfunction
160
161function Test_breakindent08a()
162 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100163 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list')
164 let lines=s:screen_lines(line('.'),10)
165 let expect=[
166\ " 2 ^Iabcd",
167\ " # opq",
168\ " # BCD",
169\ ]
170 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100171 call s:close_windows('set sbr=')
172endfunction
173
174function Test_breakindent09()
175 " breakindent set and shift by 1, Number and list set sbr=#
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100176 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list')
177 let lines=s:screen_lines(line('.'),10)
178 let expect=[
179\ " 2 ^Iabcd",
180\ " #op",
181\ " #AB",
182\ ]
183 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100184 call s:close_windows('set sbr=')
185endfunction
186
187function Test_breakindent10()
188 " breakindent set, Number set sbr=~
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100189 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100190 " make sure, cache is invalidated!
191 set ts=8
192 redraw!
193 set ts=4
194 redraw!
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100195 let lines=s:screen_lines(line('.'),10)
196 let expect=[
197\ " 2 ab",
198\ "~ mn",
199\ "~ yz",
200\ ]
201 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100202 call s:close_windows('set sbr= cpo-=n')
203endfunction
204
205function Test_breakindent11()
206 " test strdisplaywidth()
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100207 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100208 let text=getline(2)
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=')
212endfunction
213
214function Test_breakindent12()
215 " test breakindent with long indent
216 let s:input="\t\t\t\t\t{"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100217 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)
219 let expect=[
220\ " 2 >--->--->--->",
221\ " ---{ ",
222\ "~ ",
223\ ]
224 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100225 call s:close_windows('set nuw=4 listchars=')
226endfunction
227
228function Test_breakindent13()
229 let s:input=""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100230 call s:test_windows('setl breakindent briopt=min:10 ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100231 vert resize 20
232 call setline(1, [" a\tb\tc\td\te", " z y x w v"])
233 1
234 norm! fbgj"ayl
235 2
236 norm! fygj"byl
237 call assert_equal('d', @a)
238 call assert_equal('w', @b)
239 call s:close_windows()
240endfunction
241
242function Test_breakindent14()
243 let s:input=""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100244 call s:test_windows('setl breakindent briopt= ts=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100245 vert resize 30
246 norm! 3a1234567890
247 norm! a abcde
248 exec "norm! 0\<C-V>tex"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100249 let lines=s:screen_lines(line('.'),8)
250 let expect=[
251\ "e ",
252\ "~ ",
253\ "~ ",
254\ ]
255 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100256 call s:close_windows()
257endfunction
258
259function Test_breakindent15()
260 let s:input=""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100261 call s:test_windows('setl breakindent briopt= ts=8 sw=8')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100262 vert resize 30
263 norm! 4a1234567890
264 exe "normal! >>\<C-V>3f0x"
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100265 let lines=s:screen_lines(line('.'),20)
266 let expect=[
267\ " 1234567890 ",
268\ "~ ",
269\ "~ ",
270\ ]
271 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100272 call s:close_windows()
273endfunction
274
275function Test_breakindent16()
276 " Check that overlong lines are indented correctly.
Bram Moolenaar6c896862016-11-17 19:46:51 +0100277 let s:input=""
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100278 call s:test_windows('setl breakindent briopt=min:0 ts=4')
Bram Moolenaar6c896862016-11-17 19:46:51 +0100279 call setline(1, "\t".repeat("1234567890", 10))
280 resize 6
281 norm! 1gg$
282 redraw!
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100283 let lines=s:screen_lines(1,10)
284 let expect=[
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100285\ " 789012",
286\ " 345678",
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100287\ " 901234",
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100288\ ]
289 call s:compare_lines(expect, lines)
290 let lines=s:screen_lines(4,10)
291 let expect=[
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100292\ " 567890",
293\ " 123456",
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100294\ " 7890 ",
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100295\ ]
296 call s:compare_lines(expect, lines)
Bram Moolenaar6c896862016-11-17 19:46:51 +0100297 call s:close_windows()
298endfunction