Mercurial > vim
comparison src/testdir/test_breakindent.vim @ 10843:678edb254216 v8.0.0311
patch 8.0.0311: linebreak tests are old style
commit https://github.com/vim/vim/commit/544d3bc9f0e494cb712a33b61558b8e8e12b1e0b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 5 21:14:50 2017 +0100
patch 8.0.0311: linebreak tests are old style
Problem: Linebreak tests are old style.
Solution: Turn the tests into new style. Share utility functions. (Ozaki
Kiichi, closes #1444)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 05 Feb 2017 21:15:04 +0100 |
parents | 957a1d560bda |
children | c004e17fa36b |
comparison
equal
deleted
inserted
replaced
10842:cea113b1210b | 10843:678edb254216 |
---|---|
1 " Test for breakindent | 1 " Test for breakindent |
2 " | 2 " |
3 " Note: if you get strange failures when adding new tests, it might be that | 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. | 4 " while the test is run, the breakindent cacheing gets in its way. |
5 " It helps to change the tabastop setting and force a redraw (e.g. see | 5 " It helps to change the tabstop setting and force a redraw (e.g. see |
6 " Test_breakindent08()) | 6 " Test_breakindent08()) |
7 if !exists('+breakindent') | 7 if !exists('+breakindent') |
8 finish | 8 finish |
9 endif | 9 endif |
10 | 10 |
11 source view_util.vim | |
12 | |
11 let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" | 13 let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" |
12 | 14 |
13 function s:screenline(lnum, width) abort | 15 function s:screen_lines(lnum, width) abort |
14 " always get 4 screen lines | 16 return ScreenLines([a:lnum, a:lnum + 2], a:width) |
15 redraw! | 17 endfunction |
16 let line = [] | 18 |
17 for j in range(3) | 19 function! s:compare_lines(expect, actual) |
18 for c in range(1, a:width) | 20 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) |
19 call add(line, nr2char(screenchar(a:lnum+j, c))) | 21 endfunction |
20 endfor | 22 |
21 call add(line, "\n") | 23 function s:test_windows(...) |
22 endfor | 24 call NewWindow(10, 20) |
23 return join(line, '') | 25 setl ts=4 sw=4 sts=4 breakindent |
24 endfunction | |
25 | |
26 function s:testwindows(...) | |
27 10new | |
28 vsp | |
29 vert resize 20 | |
30 setl ts=4 sw=4 sts=4 breakindent | |
31 put =s:input | 26 put =s:input |
32 if a:0 | 27 exe get(a:000, 0, '') |
33 exe a:1 | |
34 endif | |
35 endfunction | 28 endfunction |
36 | 29 |
37 function s:close_windows(...) | 30 function s:close_windows(...) |
38 bw! | 31 call CloseWindow() |
39 if a:0 | 32 exe get(a:000, 0, '') |
40 exe a:1 | |
41 endif | |
42 unlet! g:line g:expect | |
43 endfunction | 33 endfunction |
44 | 34 |
45 function Test_breakindent01() | 35 function Test_breakindent01() |
46 " simple breakindent test | 36 " simple breakindent test |
47 call s:testwindows('setl briopt=min:0') | 37 call s:test_windows('setl briopt=min:0') |
48 let g:line=s:screenline(line('.'),8) | 38 let lines=s:screen_lines(line('.'),8) |
49 let g:expect=" abcd\n qrst\n GHIJ\n" | 39 let expect=[ |
50 call assert_equal(g:expect, g:line) | 40 \ " abcd", |
41 \ " qrst", | |
42 \ " GHIJ", | |
43 \ ] | |
44 call s:compare_lines(expect, lines) | |
51 call s:close_windows() | 45 call s:close_windows() |
52 endfunction | 46 endfunction |
53 | 47 |
54 function Test_breakindent02() | 48 function Test_breakindent02() |
55 " simple breakindent test with showbreak set | 49 " simple breakindent test with showbreak set |
56 call s:testwindows('setl briopt=min:0 sbr=>>') | 50 call s:test_windows('setl briopt=min:0 sbr=>>') |
57 let g:line=s:screenline(line('.'),8) | 51 let lines=s:screen_lines(line('.'),8) |
58 let g:expect=" abcd\n >>qr\n >>EF\n" | 52 let expect=[ |
59 call assert_equal(g:expect, g:line) | 53 \ " abcd", |
54 \ " >>qr", | |
55 \ " >>EF", | |
56 \ ] | |
57 call s:compare_lines(expect, lines) | |
60 call s:close_windows('set sbr=') | 58 call s:close_windows('set sbr=') |
61 endfunction | 59 endfunction |
62 | 60 |
63 function Test_breakindent03() | 61 function Test_breakindent03() |
64 " simple breakindent test with showbreak set and briopt including sbr | 62 " simple breakindent test with showbreak set and briopt including sbr |
65 call s:testwindows('setl briopt=sbr,min:0 sbr=++') | 63 call s:test_windows('setl briopt=sbr,min:0 sbr=++') |
66 let g:line=s:screenline(line('.'),8) | 64 let lines=s:screen_lines(line('.'),8) |
67 let g:expect=" abcd\n++ qrst\n++ GHIJ\n" | 65 let expect=[ |
68 call assert_equal(g:expect, g:line) | 66 \ " abcd", |
67 \ "++ qrst", | |
68 \ "++ GHIJ", | |
69 \ ] | |
70 call s:compare_lines(expect, lines) | |
69 " clean up | 71 " clean up |
70 call s:close_windows('set sbr=') | 72 call s:close_windows('set sbr=') |
71 endfunction | 73 endfunction |
72 | 74 |
73 function Test_breakindent04() | 75 function Test_breakindent04() |
74 " breakindent set with min width 18 | 76 " breakindent set with min width 18 |
75 call s:testwindows('setl sbr= briopt=min:18') | 77 call s:test_windows('setl sbr= briopt=min:18') |
76 let g:line=s:screenline(line('.'),8) | 78 let lines=s:screen_lines(line('.'),8) |
77 let g:expect=" abcd\n qrstuv\n IJKLMN\n" | 79 let expect=[ |
78 call assert_equal(g:expect, g:line) | 80 \ " abcd", |
81 \ " qrstuv", | |
82 \ " IJKLMN", | |
83 \ ] | |
84 call s:compare_lines(expect, lines) | |
79 " clean up | 85 " clean up |
80 call s:close_windows('set sbr=') | 86 call s:close_windows('set sbr=') |
81 endfunction | 87 endfunction |
82 | 88 |
83 function Test_breakindent05() | 89 function Test_breakindent05() |
84 " breakindent set and shift by 2 | 90 " breakindent set and shift by 2 |
85 call s:testwindows('setl briopt=shift:2,min:0') | 91 call s:test_windows('setl briopt=shift:2,min:0') |
86 let g:line=s:screenline(line('.'),8) | 92 let lines=s:screen_lines(line('.'),8) |
87 let g:expect=" abcd\n qr\n EF\n" | 93 let expect=[ |
88 call assert_equal(g:expect, g:line) | 94 \ " abcd", |
95 \ " qr", | |
96 \ " EF", | |
97 \ ] | |
98 call s:compare_lines(expect, lines) | |
89 call s:close_windows() | 99 call s:close_windows() |
90 endfunction | 100 endfunction |
91 | 101 |
92 function Test_breakindent06() | 102 function Test_breakindent06() |
93 " breakindent set and shift by -1 | 103 " breakindent set and shift by -1 |
94 call s:testwindows('setl briopt=shift:-1,min:0') | 104 call s:test_windows('setl briopt=shift:-1,min:0') |
95 let g:line=s:screenline(line('.'),8) | 105 let lines=s:screen_lines(line('.'),8) |
96 let g:expect=" abcd\n qrstu\n HIJKL\n" | 106 let expect=[ |
97 call assert_equal(g:expect, g:line) | 107 \ " abcd", |
108 \ " qrstu", | |
109 \ " HIJKL", | |
110 \ ] | |
111 call s:compare_lines(expect, lines) | |
98 call s:close_windows() | 112 call s:close_windows() |
99 endfunction | 113 endfunction |
100 | 114 |
101 function Test_breakindent07() | 115 function Test_breakindent07() |
102 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr | 116 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr |
103 call s:testwindows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n') | 117 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n') |
104 let g:line=s:screenline(line('.'),10) | 118 let lines=s:screen_lines(line('.'),10) |
105 let g:expect=" 2 ab\n? m\n? x\n" | 119 let expect=[ |
106 call assert_equal(g:expect, g:line) | 120 \ " 2 ab", |
121 \ "? m", | |
122 \ "? x", | |
123 \ ] | |
124 call s:compare_lines(expect, lines) | |
107 " clean up | 125 " clean up |
108 call s:close_windows('set sbr= cpo-=n') | 126 call s:close_windows('set sbr= cpo-=n') |
109 endfunction | 127 endfunction |
110 | 128 |
111 function Test_breakindent07a() | 129 function Test_breakindent07a() |
112 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr | 130 " breakindent set and shift by 1, Number set sbr=? and briopt:sbr |
113 call s:testwindows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4') | 131 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4') |
114 let g:line=s:screenline(line('.'),10) | 132 let lines=s:screen_lines(line('.'),10) |
115 let g:expect=" 2 ab\n ? m\n ? x\n" | 133 let expect=[ |
116 call assert_equal(g:expect, g:line) | 134 \ " 2 ab", |
135 \ " ? m", | |
136 \ " ? x", | |
137 \ ] | |
138 call s:compare_lines(expect, lines) | |
117 " clean up | 139 " clean up |
118 call s:close_windows('set sbr=') | 140 call s:close_windows('set sbr=') |
119 endfunction | 141 endfunction |
120 | 142 |
121 function Test_breakindent08() | 143 function Test_breakindent08() |
122 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr | 144 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr |
123 call s:testwindows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4') | 145 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4') |
124 " make sure, cache is invalidated! | 146 " make sure, cache is invalidated! |
125 set ts=8 | 147 set ts=8 |
126 redraw! | 148 redraw! |
127 set ts=4 | 149 set ts=4 |
128 redraw! | 150 redraw! |
129 let g:line=s:screenline(line('.'),10) | 151 let lines=s:screen_lines(line('.'),10) |
130 let g:expect=" 2 ^Iabcd\n# opq\n# BCD\n" | 152 let expect=[ |
131 call assert_equal(g:expect, g:line) | 153 \ " 2 ^Iabcd", |
154 \ "# opq", | |
155 \ "# BCD", | |
156 \ ] | |
157 call s:compare_lines(expect, lines) | |
132 call s:close_windows('set sbr= cpo-=n') | 158 call s:close_windows('set sbr= cpo-=n') |
133 endfunction | 159 endfunction |
134 | 160 |
135 function Test_breakindent08a() | 161 function Test_breakindent08a() |
136 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr | 162 " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr |
137 call s:testwindows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list') | 163 call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list') |
138 let g:line=s:screenline(line('.'),10) | 164 let lines=s:screen_lines(line('.'),10) |
139 let g:expect=" 2 ^Iabcd\n # opq\n # BCD\n" | 165 let expect=[ |
140 call assert_equal(g:expect, g:line) | 166 \ " 2 ^Iabcd", |
167 \ " # opq", | |
168 \ " # BCD", | |
169 \ ] | |
170 call s:compare_lines(expect, lines) | |
141 call s:close_windows('set sbr=') | 171 call s:close_windows('set sbr=') |
142 endfunction | 172 endfunction |
143 | 173 |
144 function Test_breakindent09() | 174 function Test_breakindent09() |
145 " breakindent set and shift by 1, Number and list set sbr=# | 175 " breakindent set and shift by 1, Number and list set sbr=# |
146 call s:testwindows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list') | 176 call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list') |
147 let g:line=s:screenline(line('.'),10) | 177 let lines=s:screen_lines(line('.'),10) |
148 let g:expect=" 2 ^Iabcd\n #op\n #AB\n" | 178 let expect=[ |
149 call assert_equal(g:expect, g:line) | 179 \ " 2 ^Iabcd", |
180 \ " #op", | |
181 \ " #AB", | |
182 \ ] | |
183 call s:compare_lines(expect, lines) | |
150 call s:close_windows('set sbr=') | 184 call s:close_windows('set sbr=') |
151 endfunction | 185 endfunction |
152 | 186 |
153 function Test_breakindent10() | 187 function Test_breakindent10() |
154 " breakindent set, Number set sbr=~ | 188 " breakindent set, Number set sbr=~ |
155 call s:testwindows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') | 189 call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') |
156 " make sure, cache is invalidated! | 190 " make sure, cache is invalidated! |
157 set ts=8 | 191 set ts=8 |
158 redraw! | 192 redraw! |
159 set ts=4 | 193 set ts=4 |
160 redraw! | 194 redraw! |
161 let g:line=s:screenline(line('.'),10) | 195 let lines=s:screen_lines(line('.'),10) |
162 let g:expect=" 2 ab\n~ mn\n~ yz\n" | 196 let expect=[ |
163 call assert_equal(g:expect, g:line) | 197 \ " 2 ab", |
198 \ "~ mn", | |
199 \ "~ yz", | |
200 \ ] | |
201 call s:compare_lines(expect, lines) | |
164 call s:close_windows('set sbr= cpo-=n') | 202 call s:close_windows('set sbr= cpo-=n') |
165 endfunction | 203 endfunction |
166 | 204 |
167 function Test_breakindent11() | 205 function Test_breakindent11() |
168 " test strdisplaywidth() | 206 " test strdisplaywidth() |
169 call s:testwindows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') | 207 call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') |
170 let text=getline(2) | 208 let text=getline(2) |
171 let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times | 209 let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times |
172 call assert_equal(width, strdisplaywidth(text)) | 210 call assert_equal(width, strdisplaywidth(text)) |
173 call s:close_windows('set sbr=') | 211 call s:close_windows('set sbr=') |
174 endfunction | 212 endfunction |
175 | 213 |
176 function Test_breakindent12() | 214 function Test_breakindent12() |
177 " test breakindent with long indent | 215 " test breakindent with long indent |
178 let s:input="\t\t\t\t\t{" | 216 let s:input="\t\t\t\t\t{" |
179 call s:testwindows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-') | 217 call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-') |
180 let g:line=s:screenline(2,16) | 218 let lines=s:screen_lines(2,16) |
181 let g:expect=" 2 >--->--->--->\n ---{ \n~ \n" | 219 let expect=[ |
182 call assert_equal(g:expect, g:line) | 220 \ " 2 >--->--->--->", |
221 \ " ---{ ", | |
222 \ "~ ", | |
223 \ ] | |
224 call s:compare_lines(expect, lines) | |
183 call s:close_windows('set nuw=4 listchars=') | 225 call s:close_windows('set nuw=4 listchars=') |
184 endfunction | 226 endfunction |
185 | 227 |
186 function Test_breakindent13() | 228 function Test_breakindent13() |
187 let s:input="" | 229 let s:input="" |
188 call s:testwindows('setl breakindent briopt=min:10 ts=8') | 230 call s:test_windows('setl breakindent briopt=min:10 ts=8') |
189 vert resize 20 | 231 vert resize 20 |
190 call setline(1, [" a\tb\tc\td\te", " z y x w v"]) | 232 call setline(1, [" a\tb\tc\td\te", " z y x w v"]) |
191 1 | 233 1 |
192 norm! fbgj"ayl | 234 norm! fbgj"ayl |
193 2 | 235 2 |
197 call s:close_windows() | 239 call s:close_windows() |
198 endfunction | 240 endfunction |
199 | 241 |
200 function Test_breakindent14() | 242 function Test_breakindent14() |
201 let s:input="" | 243 let s:input="" |
202 call s:testwindows('setl breakindent briopt= ts=8') | 244 call s:test_windows('setl breakindent briopt= ts=8') |
203 vert resize 30 | 245 vert resize 30 |
204 norm! 3a1234567890 | 246 norm! 3a1234567890 |
205 norm! a abcde | 247 norm! a abcde |
206 exec "norm! 0\<C-V>tex" | 248 exec "norm! 0\<C-V>tex" |
207 let g:line=s:screenline(line('.'),8) | 249 let lines=s:screen_lines(line('.'),8) |
208 let g:expect="e \n~ \n~ \n" | 250 let expect=[ |
209 call assert_equal(g:expect, g:line) | 251 \ "e ", |
252 \ "~ ", | |
253 \ "~ ", | |
254 \ ] | |
255 call s:compare_lines(expect, lines) | |
210 call s:close_windows() | 256 call s:close_windows() |
211 endfunction | 257 endfunction |
212 | 258 |
213 function Test_breakindent15() | 259 function Test_breakindent15() |
214 let s:input="" | 260 let s:input="" |
215 call s:testwindows('setl breakindent briopt= ts=8 sw=8') | 261 call s:test_windows('setl breakindent briopt= ts=8 sw=8') |
216 vert resize 30 | 262 vert resize 30 |
217 norm! 4a1234567890 | 263 norm! 4a1234567890 |
218 exe "normal! >>\<C-V>3f0x" | 264 exe "normal! >>\<C-V>3f0x" |
219 let g:line=s:screenline(line('.'),20) | 265 let lines=s:screen_lines(line('.'),20) |
220 let g:expect=" 1234567890 \n~ \n~ \n" | 266 let expect=[ |
221 call assert_equal(g:expect, g:line) | 267 \ " 1234567890 ", |
268 \ "~ ", | |
269 \ "~ ", | |
270 \ ] | |
271 call s:compare_lines(expect, lines) | |
222 call s:close_windows() | 272 call s:close_windows() |
223 endfunction | 273 endfunction |
224 | 274 |
225 function Test_breakindent16() | 275 function Test_breakindent16() |
226 " Check that overlong lines are indented correctly. | 276 " Check that overlong lines are indented correctly. |
227 " TODO: currently it does not fail even when the bug is not fixed. | 277 " TODO: currently it does not fail even when the bug is not fixed. |
228 let s:input="" | 278 let s:input="" |
229 call s:testwindows('setl breakindent briopt=min:0 ts=4') | 279 call s:test_windows('setl breakindent briopt=min:0 ts=4') |
230 call setline(1, "\t".repeat("1234567890", 10)) | 280 call setline(1, "\t".repeat("1234567890", 10)) |
231 resize 6 | 281 resize 6 |
232 norm! 1gg$ | 282 norm! 1gg$ |
233 redraw! | 283 redraw! |
234 let g:line=s:screenline(1,10) | 284 let lines=s:screen_lines(1,10) |
235 let g:expect=" 123456\n 789012\n 345678\n" | 285 let expect=[ |
236 call assert_equal(g:expect, g:line) | 286 \ " 123456", |
237 let g:line=s:screenline(4,10) | 287 \ " 789012", |
238 let g:expect=" 901234\n 567890\n 123456\n" | 288 \ " 345678", |
239 call assert_equal(g:expect, g:line) | 289 \ ] |
240 call s:close_windows() | 290 call s:compare_lines(expect, lines) |
241 endfunction | 291 let lines=s:screen_lines(4,10) |
292 let expect=[ | |
293 \ " 901234", | |
294 \ " 567890", | |
295 \ " 123456", | |
296 \ ] | |
297 call s:compare_lines(expect, lines) | |
298 call s:close_windows() | |
299 endfunction |