Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 1 | " 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 Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 5 | " It helps to change the tabstop setting and force a redraw (e.g. see |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 6 | " Test_breakindent08()) |
| 7 | if !exists('+breakindent') |
| 8 | finish |
| 9 | endif |
| 10 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 11 | source view_util.vim |
| 12 | |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 13 | let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" |
| 14 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 15 | function s:screen_lines(lnum, width) abort |
| 16 | return ScreenLines([a:lnum, a:lnum + 2], a:width) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 17 | endfunction |
| 18 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 19 | function! s:compare_lines(expect, actual) |
| 20 | call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) |
| 21 | endfunction |
| 22 | |
| 23 | function s:test_windows(...) |
| 24 | call NewWindow(10, 20) |
| 25 | setl ts=4 sw=4 sts=4 breakindent |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 26 | put =s:input |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 27 | exe get(a:000, 0, '') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 28 | endfunction |
| 29 | |
| 30 | function s:close_windows(...) |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 31 | call CloseWindow() |
| 32 | exe get(a:000, 0, '') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 33 | endfunction |
| 34 | |
| 35 | function Test_breakindent01() |
| 36 | " simple breakindent test |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 37 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 45 | call s:close_windows() |
| 46 | endfunction |
| 47 | |
| 48 | function Test_breakindent02() |
| 49 | " simple breakindent test with showbreak set |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 50 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 58 | call s:close_windows('set sbr=') |
| 59 | endfunction |
| 60 | |
| 61 | function Test_breakindent03() |
| 62 | " simple breakindent test with showbreak set and briopt including sbr |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 63 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 71 | " clean up |
| 72 | call s:close_windows('set sbr=') |
| 73 | endfunction |
| 74 | |
| 75 | function Test_breakindent04() |
| 76 | " breakindent set with min width 18 |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 77 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 85 | " clean up |
| 86 | call s:close_windows('set sbr=') |
| 87 | endfunction |
| 88 | |
| 89 | function Test_breakindent05() |
| 90 | " breakindent set and shift by 2 |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 91 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 99 | call s:close_windows() |
| 100 | endfunction |
| 101 | |
| 102 | function Test_breakindent06() |
| 103 | " breakindent set and shift by -1 |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 104 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 112 | call s:close_windows() |
| 113 | endfunction |
| 114 | |
| 115 | function Test_breakindent07() |
| 116 | " breakindent set and shift by 1, Number set sbr=? and briopt:sbr |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 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) |
| 119 | let expect=[ |
| 120 | \ " 2 ab", |
| 121 | \ "? m", |
| 122 | \ "? x", |
| 123 | \ ] |
| 124 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 125 | " clean up |
| 126 | call s:close_windows('set sbr= cpo-=n') |
| 127 | endfunction |
| 128 | |
| 129 | function Test_breakindent07a() |
| 130 | " breakindent set and shift by 1, Number set sbr=? and briopt:sbr |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 131 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 139 | " clean up |
| 140 | call s:close_windows('set sbr=') |
| 141 | endfunction |
| 142 | |
| 143 | function Test_breakindent08() |
| 144 | " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 145 | call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 146 | " make sure, cache is invalidated! |
| 147 | set ts=8 |
| 148 | redraw! |
| 149 | set ts=4 |
| 150 | redraw! |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 151 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 158 | call s:close_windows('set sbr= cpo-=n') |
| 159 | endfunction |
| 160 | |
| 161 | function Test_breakindent08a() |
| 162 | " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 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) |
| 165 | let expect=[ |
| 166 | \ " 2 ^Iabcd", |
| 167 | \ " # opq", |
| 168 | \ " # BCD", |
| 169 | \ ] |
| 170 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 171 | call s:close_windows('set sbr=') |
| 172 | endfunction |
| 173 | |
| 174 | function Test_breakindent09() |
| 175 | " breakindent set and shift by 1, Number and list set sbr=# |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 176 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 184 | call s:close_windows('set sbr=') |
| 185 | endfunction |
| 186 | |
| 187 | function Test_breakindent10() |
| 188 | " breakindent set, Number set sbr=~ |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 189 | call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 190 | " make sure, cache is invalidated! |
| 191 | set ts=8 |
| 192 | redraw! |
| 193 | set ts=4 |
| 194 | redraw! |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 195 | 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 Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 202 | call s:close_windows('set sbr= cpo-=n') |
| 203 | endfunction |
| 204 | |
| 205 | function Test_breakindent11() |
| 206 | " test strdisplaywidth() |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 207 | call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 208 | 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=') |
| 212 | endfunction |
| 213 | |
| 214 | function Test_breakindent12() |
| 215 | " test breakindent with long indent |
| 216 | let s:input="\t\t\t\t\t{" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 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) |
| 219 | let expect=[ |
| 220 | \ " 2 >--->--->--->", |
| 221 | \ " ---{ ", |
| 222 | \ "~ ", |
| 223 | \ ] |
| 224 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 225 | call s:close_windows('set nuw=4 listchars=') |
| 226 | endfunction |
| 227 | |
| 228 | function Test_breakindent13() |
| 229 | let s:input="" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 230 | call s:test_windows('setl breakindent briopt=min:10 ts=8') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 231 | 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() |
| 240 | endfunction |
| 241 | |
| 242 | function Test_breakindent14() |
| 243 | let s:input="" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 244 | call s:test_windows('setl breakindent briopt= ts=8') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 245 | vert resize 30 |
| 246 | norm! 3a1234567890 |
| 247 | norm! a abcde |
| 248 | exec "norm! 0\<C-V>tex" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 249 | let lines=s:screen_lines(line('.'),8) |
| 250 | let expect=[ |
| 251 | \ "e ", |
| 252 | \ "~ ", |
| 253 | \ "~ ", |
| 254 | \ ] |
| 255 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 256 | call s:close_windows() |
| 257 | endfunction |
| 258 | |
| 259 | function Test_breakindent15() |
| 260 | let s:input="" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 261 | call s:test_windows('setl breakindent briopt= ts=8 sw=8') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 262 | vert resize 30 |
| 263 | norm! 4a1234567890 |
| 264 | exe "normal! >>\<C-V>3f0x" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 265 | let lines=s:screen_lines(line('.'),20) |
| 266 | let expect=[ |
| 267 | \ " 1234567890 ", |
| 268 | \ "~ ", |
| 269 | \ "~ ", |
| 270 | \ ] |
| 271 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 272 | call s:close_windows() |
| 273 | endfunction |
| 274 | |
| 275 | function Test_breakindent16() |
| 276 | " Check that overlong lines are indented correctly. |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 277 | let s:input="" |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 278 | call s:test_windows('setl breakindent briopt=min:0 ts=4') |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 279 | call setline(1, "\t".repeat("1234567890", 10)) |
| 280 | resize 6 |
| 281 | norm! 1gg$ |
| 282 | redraw! |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 283 | let lines=s:screen_lines(1,10) |
| 284 | let expect=[ |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 285 | \ " 789012", |
| 286 | \ " 345678", |
Bram Moolenaar | abc39ab | 2017-03-01 18:04:05 +0100 | [diff] [blame] | 287 | \ " 901234", |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 288 | \ ] |
| 289 | call s:compare_lines(expect, lines) |
| 290 | let lines=s:screen_lines(4,10) |
| 291 | let expect=[ |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 292 | \ " 567890", |
| 293 | \ " 123456", |
Bram Moolenaar | abc39ab | 2017-03-01 18:04:05 +0100 | [diff] [blame] | 294 | \ " 7890 ", |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 295 | \ ] |
| 296 | call s:compare_lines(expect, lines) |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 297 | call s:close_windows() |
| 298 | endfunction |