Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 1 | " Test for variable tabstops |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature vartabs |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 6 | source view_util.vim |
Bram Moolenaar | 037c54f | 2019-04-20 23:47:46 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 8 | func s:compare_lines(expect, actual) |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 9 | call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 10 | endfunc |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 11 | |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 12 | func Test_vartabs() |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 13 | new |
| 14 | %d |
| 15 | |
| 16 | " Test normal operation of tabstops ... |
| 17 | set ts=4 |
| 18 | call setline(1, join(split('aaaaa', '\zs'), "\t")) |
| 19 | retab 8 |
| 20 | let expect = "a a\<tab>a a\<tab>a" |
| 21 | call assert_equal(expect, getline(1)) |
| 22 | |
| 23 | " ... and softtabstops |
| 24 | set ts=8 sts=6 |
| 25 | exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b" |
| 26 | let expect = "b b\<tab> b\<tab> b\<tab>b" |
| 27 | call assert_equal(expect, getline(1)) |
| 28 | |
| 29 | " Test variable tabstops. |
| 30 | set sts=0 vts=4,8,4,8 |
| 31 | exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c" |
| 32 | retab 8 |
| 33 | let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c" |
| 34 | call assert_equal(expect, getline(1)) |
| 35 | |
| 36 | set et vts=4,8,4,8 |
| 37 | exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d" |
| 38 | let expect = "d d d d d d" |
| 39 | call assert_equal(expect, getline(1)) |
| 40 | |
| 41 | " Changing ts should have no effect if vts is in use. |
| 42 | call cursor(1, 1) |
| 43 | set ts=6 |
| 44 | exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e" |
| 45 | let expect = "e e e e e e" |
| 46 | call assert_equal(expect, getline(1)) |
| 47 | |
| 48 | " Clearing vts should revert to using ts. |
| 49 | set vts= |
| 50 | exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f" |
| 51 | let expect = "f f f f f f" |
| 52 | call assert_equal(expect, getline(1)) |
| 53 | |
| 54 | " Test variable softtabstops. |
| 55 | set noet ts=8 vsts=12,2,6 |
| 56 | exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g" |
| 57 | let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g" |
| 58 | call assert_equal(expect, getline(1)) |
| 59 | |
| 60 | " Variable tabstops and softtabstops combined. |
| 61 | set vsts=6,12,8 vts=4,6,8 |
| 62 | exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h" |
| 63 | let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h" |
| 64 | call assert_equal(expect, getline(1)) |
| 65 | |
| 66 | " Retab with a single value, not using vts. |
| 67 | set ts=8 sts=0 vts= vsts= |
| 68 | exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i" |
| 69 | retab 4 |
| 70 | let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i" |
| 71 | call assert_equal(expect, getline(1)) |
| 72 | |
| 73 | " Retab with a single value, using vts. |
| 74 | set ts=8 sts=0 vts=6 vsts= |
| 75 | exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j" |
| 76 | retab 4 |
| 77 | let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j" |
| 78 | call assert_equal(expect, getline(1)) |
| 79 | |
| 80 | " Retab with multiple values, not using vts. |
| 81 | set ts=6 sts=0 vts= vsts= |
| 82 | exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k" |
| 83 | retab 4,8 |
| 84 | let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k" |
| 85 | call assert_equal(expect, getline(1)) |
| 86 | |
| 87 | " Retab with multiple values, using vts. |
| 88 | set ts=8 sts=0 vts=6 vsts= |
| 89 | exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l" |
| 90 | retab 4,8 |
| 91 | let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l" |
| 92 | call assert_equal(expect, getline(1)) |
| 93 | |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame] | 94 | " Test for 'retab' with vts |
| 95 | set ts=8 sts=0 vts=5,3,6,2 vsts= |
| 96 | exe "norm! S l" |
| 97 | .retab! |
| 98 | call assert_equal("\t\t\t\tl", getline(1)) |
| 99 | |
Bram Moolenaar | 8e7d622 | 2020-12-18 19:49:56 +0100 | [diff] [blame] | 100 | " Test for 'retab' with same values as vts |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame] | 101 | set ts=8 sts=0 vts=5,3,6,2 vsts= |
| 102 | exe "norm! S l" |
| 103 | .retab! 5,3,6,2 |
| 104 | call assert_equal("\t\t\t\tl", getline(1)) |
| 105 | |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 106 | " Check that global and local values are set. |
| 107 | set ts=4 vts=6 sts=8 vsts=10 |
| 108 | call assert_equal(&ts, 4) |
| 109 | call assert_equal(&vts, '6') |
| 110 | call assert_equal(&sts, 8) |
| 111 | call assert_equal(&vsts, '10') |
| 112 | new |
| 113 | call assert_equal(&ts, 4) |
| 114 | call assert_equal(&vts, '6') |
| 115 | call assert_equal(&sts, 8) |
| 116 | call assert_equal(&vsts, '10') |
| 117 | bwipeout! |
| 118 | |
| 119 | " Check that local values only are set. |
| 120 | setlocal ts=5 vts=7 sts=9 vsts=11 |
| 121 | call assert_equal(&ts, 5) |
| 122 | call assert_equal(&vts, '7') |
| 123 | call assert_equal(&sts, 9) |
| 124 | call assert_equal(&vsts, '11') |
| 125 | new |
| 126 | call assert_equal(&ts, 4) |
| 127 | call assert_equal(&vts, '6') |
| 128 | call assert_equal(&sts, 8) |
| 129 | call assert_equal(&vsts, '10') |
| 130 | bwipeout! |
| 131 | |
| 132 | " Check that global values only are set. |
| 133 | setglobal ts=6 vts=8 sts=10 vsts=12 |
| 134 | call assert_equal(&ts, 5) |
| 135 | call assert_equal(&vts, '7') |
| 136 | call assert_equal(&sts, 9) |
| 137 | call assert_equal(&vsts, '11') |
| 138 | new |
| 139 | call assert_equal(&ts, 6) |
| 140 | call assert_equal(&vts, '8') |
| 141 | call assert_equal(&sts, 10) |
| 142 | call assert_equal(&vsts, '12') |
| 143 | bwipeout! |
| 144 | |
| 145 | set ts& vts& sts& vsts& et& |
| 146 | bwipeout! |
| 147 | endfunc |
| 148 | |
Bram Moolenaar | fc88df4 | 2022-02-05 11:13:05 +0000 | [diff] [blame^] | 149 | func Test_retab_invalid_arg() |
| 150 | new |
| 151 | call setline(1, "\ttext") |
| 152 | retab 0 |
| 153 | call assert_fails("retab -8", 'E487: Argument must be positive') |
| 154 | call assert_fails("retab 10000", 'E475:') |
| 155 | call assert_fails("retab 720575940379279360", 'E475:') |
| 156 | bwipe! |
| 157 | endfunc |
| 158 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 159 | func Test_vartabs_breakindent() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 160 | CheckOption breakindent |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 161 | new |
| 162 | %d |
| 163 | |
| 164 | " Test normal operation of tabstops ... |
| 165 | set ts=4 |
| 166 | call setline(1, join(split('aaaaa', '\zs'), "\t")) |
| 167 | retab 8 |
| 168 | let expect = "a a\<tab>a a\<tab>a" |
| 169 | call assert_equal(expect, getline(1)) |
| 170 | |
| 171 | " ... and softtabstops |
| 172 | set ts=8 sts=6 |
| 173 | exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b" |
| 174 | let expect = "b b\<tab> b\<tab> b\<tab>b" |
| 175 | call assert_equal(expect, getline(1)) |
| 176 | |
| 177 | " Test variable tabstops. |
| 178 | set sts=0 vts=4,8,4,8 |
| 179 | exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c" |
| 180 | retab 8 |
| 181 | let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c" |
| 182 | call assert_equal(expect, getline(1)) |
| 183 | |
| 184 | set et vts=4,8,4,8 |
| 185 | exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d" |
| 186 | let expect = "d d d d d d" |
| 187 | call assert_equal(expect, getline(1)) |
| 188 | |
| 189 | " Changing ts should have no effect if vts is in use. |
| 190 | call cursor(1, 1) |
| 191 | set ts=6 |
| 192 | exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e" |
| 193 | let expect = "e e e e e e" |
| 194 | call assert_equal(expect, getline(1)) |
| 195 | |
| 196 | " Clearing vts should revert to using ts. |
| 197 | set vts= |
| 198 | exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f" |
| 199 | let expect = "f f f f f f" |
| 200 | call assert_equal(expect, getline(1)) |
| 201 | |
| 202 | " Test variable softtabstops. |
| 203 | set noet ts=8 vsts=12,2,6 |
| 204 | exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g" |
| 205 | let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g" |
| 206 | call assert_equal(expect, getline(1)) |
| 207 | |
| 208 | " Variable tabstops and softtabstops combined. |
| 209 | set vsts=6,12,8 vts=4,6,8 |
| 210 | exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h" |
| 211 | let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h" |
| 212 | call assert_equal(expect, getline(1)) |
| 213 | |
| 214 | " Retab with a single value, not using vts. |
| 215 | set ts=8 sts=0 vts= vsts= |
| 216 | exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i" |
| 217 | retab 4 |
| 218 | let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i" |
| 219 | call assert_equal(expect, getline(1)) |
| 220 | |
| 221 | " Retab with a single value, using vts. |
| 222 | set ts=8 sts=0 vts=6 vsts= |
| 223 | exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j" |
| 224 | retab 4 |
| 225 | let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j" |
| 226 | call assert_equal(expect, getline(1)) |
| 227 | |
| 228 | " Retab with multiple values, not using vts. |
| 229 | set ts=6 sts=0 vts= vsts= |
| 230 | exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k" |
| 231 | retab 4,8 |
| 232 | let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k" |
| 233 | call assert_equal(expect, getline(1)) |
| 234 | |
| 235 | " Retab with multiple values, using vts. |
| 236 | set ts=8 sts=0 vts=6 vsts= |
| 237 | exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l" |
| 238 | retab 4,8 |
| 239 | let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l" |
| 240 | call assert_equal(expect, getline(1)) |
| 241 | |
| 242 | " Check that global and local values are set. |
| 243 | set ts=4 vts=6 sts=8 vsts=10 |
| 244 | call assert_equal(&ts, 4) |
| 245 | call assert_equal(&vts, '6') |
| 246 | call assert_equal(&sts, 8) |
| 247 | call assert_equal(&vsts, '10') |
| 248 | new |
| 249 | call assert_equal(&ts, 4) |
| 250 | call assert_equal(&vts, '6') |
| 251 | call assert_equal(&sts, 8) |
| 252 | call assert_equal(&vsts, '10') |
| 253 | bwipeout! |
| 254 | |
| 255 | " Check that local values only are set. |
| 256 | setlocal ts=5 vts=7 sts=9 vsts=11 |
| 257 | call assert_equal(&ts, 5) |
| 258 | call assert_equal(&vts, '7') |
| 259 | call assert_equal(&sts, 9) |
| 260 | call assert_equal(&vsts, '11') |
| 261 | new |
| 262 | call assert_equal(&ts, 4) |
| 263 | call assert_equal(&vts, '6') |
| 264 | call assert_equal(&sts, 8) |
| 265 | call assert_equal(&vsts, '10') |
| 266 | bwipeout! |
| 267 | |
| 268 | " Check that global values only are set. |
| 269 | setglobal ts=6 vts=8 sts=10 vsts=12 |
| 270 | call assert_equal(&ts, 5) |
| 271 | call assert_equal(&vts, '7') |
| 272 | call assert_equal(&sts, 9) |
| 273 | call assert_equal(&vsts, '11') |
| 274 | new |
| 275 | call assert_equal(&ts, 6) |
| 276 | call assert_equal(&vts, '8') |
| 277 | call assert_equal(&sts, 10) |
| 278 | call assert_equal(&vsts, '12') |
| 279 | bwipeout! |
| 280 | |
| 281 | bwipeout! |
| 282 | endfunc |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 283 | |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 284 | func Test_vartabs_linebreak() |
Bram Moolenaar | 307ac5c | 2018-06-28 22:23:00 +0200 | [diff] [blame] | 285 | if winwidth(0) < 40 |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 286 | return |
| 287 | endif |
| 288 | new |
Bram Moolenaar | 307ac5c | 2018-06-28 22:23:00 +0200 | [diff] [blame] | 289 | 40vnew |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 290 | %d |
Bram Moolenaar | 307ac5c | 2018-06-28 22:23:00 +0200 | [diff] [blame] | 291 | setl linebreak vartabstop=10,20,30,40 |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 292 | call setline(1, "\tx\tx\tx\tx") |
| 293 | |
Bram Moolenaar | 307ac5c | 2018-06-28 22:23:00 +0200 | [diff] [blame] | 294 | let expect = [' x ', |
| 295 | \ 'x x ', |
| 296 | \ 'x '] |
| 297 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 298 | call s:compare_lines(expect, lines) |
| 299 | setl list listchars=tab:>- |
| 300 | let expect = ['>---------x>------------------ ', |
| 301 | \ 'x>------------------x>------------------', |
| 302 | \ 'x '] |
| 303 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 304 | call s:compare_lines(expect, lines) |
| 305 | setl linebreak vartabstop=40 |
| 306 | let expect = ['>---------------------------------------', |
| 307 | \ 'x>--------------------------------------', |
| 308 | \ 'x>--------------------------------------', |
| 309 | \ 'x>--------------------------------------', |
| 310 | \ 'x '] |
| 311 | let lines = ScreenLines([1, 5], winwidth(0)) |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 312 | call s:compare_lines(expect, lines) |
| 313 | |
| 314 | " cleanup |
| 315 | bw! |
| 316 | bw! |
Bram Moolenaar | 307ac5c | 2018-06-28 22:23:00 +0200 | [diff] [blame] | 317 | set nolist listchars&vim |
Bram Moolenaar | a87b72c | 2018-06-25 21:24:51 +0200 | [diff] [blame] | 318 | endfunc |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 319 | |
Bram Moolenaar | f951416 | 2018-11-22 03:08:29 +0100 | [diff] [blame] | 320 | func Test_vartabs_shiftwidth() |
| 321 | "return |
| 322 | if winwidth(0) < 40 |
| 323 | return |
| 324 | endif |
| 325 | new |
| 326 | 40vnew |
| 327 | %d |
| 328 | " setl varsofttabstop=10,20,30,40 |
| 329 | setl shiftwidth=0 vartabstop=10,20,30,40 |
| 330 | call setline(1, "x") |
| 331 | |
| 332 | " Check without any change. |
| 333 | let expect = ['x '] |
| 334 | let lines = ScreenLines(1, winwidth(0)) |
| 335 | call s:compare_lines(expect, lines) |
| 336 | " Test 1: |
| 337 | " shiftwidth depends on the indent, first check with cursor at the end of the |
| 338 | " line (which is the same as the start of the line, since there is only one |
| 339 | " character). |
| 340 | norm! $>> |
| 341 | let expect1 = [' x '] |
| 342 | let lines = ScreenLines(1, winwidth(0)) |
| 343 | call s:compare_lines(expect1, lines) |
| 344 | call assert_equal(10, shiftwidth()) |
| 345 | call assert_equal(10, shiftwidth(1)) |
| 346 | call assert_equal(20, shiftwidth(virtcol('.'))) |
| 347 | norm! $>> |
| 348 | let expect2 = [' x ', '~ '] |
| 349 | let lines = ScreenLines([1, 2], winwidth(0)) |
| 350 | call s:compare_lines(expect2, lines) |
| 351 | call assert_equal(20, shiftwidth(virtcol('.')-2)) |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 352 | call assert_equal(30, virtcol('.')->shiftwidth()) |
Bram Moolenaar | f951416 | 2018-11-22 03:08:29 +0100 | [diff] [blame] | 353 | norm! $>> |
| 354 | let expect3 = [' ', ' x ', '~ '] |
| 355 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 356 | call s:compare_lines(expect3, lines) |
| 357 | call assert_equal(30, shiftwidth(virtcol('.')-2)) |
| 358 | call assert_equal(40, shiftwidth(virtcol('.'))) |
| 359 | norm! $>> |
| 360 | let expect4 = [' ', ' ', ' x '] |
| 361 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 362 | call assert_equal(40, shiftwidth(virtcol('.'))) |
| 363 | call s:compare_lines(expect4, lines) |
| 364 | |
| 365 | " Test 2: Put the cursor at the first column, result should be the same |
| 366 | call setline(1, "x") |
| 367 | norm! 0>> |
| 368 | let lines = ScreenLines(1, winwidth(0)) |
| 369 | call s:compare_lines(expect1, lines) |
| 370 | norm! 0>> |
| 371 | let lines = ScreenLines([1, 2], winwidth(0)) |
| 372 | call s:compare_lines(expect2, lines) |
| 373 | norm! 0>> |
| 374 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 375 | call s:compare_lines(expect3, lines) |
| 376 | norm! 0>> |
| 377 | let lines = ScreenLines([1, 3], winwidth(0)) |
| 378 | call s:compare_lines(expect4, lines) |
| 379 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 380 | call assert_fails('call shiftwidth([])', 'E745:') |
| 381 | |
Bram Moolenaar | f951416 | 2018-11-22 03:08:29 +0100 | [diff] [blame] | 382 | " cleanup |
| 383 | bw! |
| 384 | bw! |
| 385 | endfunc |
| 386 | |
Bram Moolenaar | 64f4107 | 2018-10-15 22:51:50 +0200 | [diff] [blame] | 387 | func Test_vartabs_failures() |
| 388 | call assert_fails('set vts=8,') |
| 389 | call assert_fails('set vsts=8,') |
| 390 | call assert_fails('set vts=8,,8') |
| 391 | call assert_fails('set vsts=8,,8') |
| 392 | call assert_fails('set vts=8,,8,') |
| 393 | call assert_fails('set vsts=8,,8,') |
| 394 | call assert_fails('set vts=,8') |
| 395 | call assert_fails('set vsts=,8') |
| 396 | endfunc |
Bram Moolenaar | 037c54f | 2019-04-20 23:47:46 +0200 | [diff] [blame] | 397 | |
| 398 | func Test_vartabs_reset() |
| 399 | set vts=8 |
| 400 | set all& |
| 401 | call assert_equal('', &vts) |
| 402 | endfunc |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame] | 403 | |
| 404 | func s:SaveCol(l) |
| 405 | call add(a:l, [col('.'), virtcol('.')]) |
| 406 | return '' |
| 407 | endfunc |
| 408 | |
| 409 | " Test for 'varsofttabstop' |
| 410 | func Test_varsofttabstop() |
| 411 | new |
| 412 | inoremap <expr> <F2> s:SaveCol(g:cols) |
| 413 | |
| 414 | set backspace=indent,eol,start |
| 415 | set varsofttabstop=6,2,5,3 |
| 416 | let g:cols = [] |
| 417 | call feedkeys("a\t\<F2>\t\<F2>\t\<F2>\t\<F2> ", 'xt') |
| 418 | call assert_equal("\t\t ", getline(1)) |
| 419 | call assert_equal([[7, 7], [2, 9], [7, 14], [3, 17]], g:cols) |
| 420 | |
| 421 | let g:cols = [] |
| 422 | call feedkeys("a\<bs>\<F2>\<bs>\<F2>\<bs>\<F2>\<bs>\<F2>\<bs>\<F2>", 'xt') |
| 423 | call assert_equal('', getline(1)) |
| 424 | call assert_equal([[3, 17], [7, 14], [2, 9], [7, 7], [1, 1]], g:cols) |
| 425 | |
| 426 | set varsofttabstop& |
| 427 | set backspace& |
| 428 | iunmap <F2> |
| 429 | close! |
| 430 | endfunc |
| 431 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 432 | " Setting 'shiftwidth' to a negative value, should set it to either the value |
| 433 | " of 'tabstop' (if 'vartabstop' is not set) or to the first value in |
| 434 | " 'vartabstop' |
| 435 | func Test_shiftwidth_vartabstop() |
| 436 | setlocal tabstop=7 vartabstop= |
| 437 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 438 | call assert_equal(7, &shiftwidth) |
| 439 | setlocal tabstop=7 vartabstop=5,7,10 |
| 440 | call assert_fails('set shiftwidth=-1', 'E487:') |
| 441 | call assert_equal(5, &shiftwidth) |
| 442 | setlocal shiftwidth& vartabstop& tabstop& |
| 443 | endfunc |
| 444 | |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame] | 445 | " vim: shiftwidth=2 sts=2 expandtab |