@@ -297,6 +297,71 @@ func Test_vartabs_linebreak()
297297 set nolist listchars &vim
298298endfunc
299299
300+ func Test_vartabs_shiftwidth ()
301+ " return
302+ if winwidth (0 ) < 40
303+ return
304+ endif
305+ new
306+ 40 vnew
307+ % d
308+ " setl varsofttabstop=10,20,30,40
309+ setl shiftwidth = 0 vartabstop = 10 ,20 ,30 ,40
310+ call setline (1 , " x" )
311+
312+ " Check without any change.
313+ let expect = [' x ' ]
314+ let lines = ScreenLines (1 , winwidth (0 ))
315+ call s: compare_lines (expect, lines )
316+ " Test 1:
317+ " shiftwidth depends on the indent, first check with cursor at the end of the
318+ " line (which is the same as the start of the line, since there is only one
319+ " character).
320+ norm! $ >>
321+ let expect1 = [' x ' ]
322+ let lines = ScreenLines (1 , winwidth (0 ))
323+ call s: compare_lines (expect1, lines )
324+ call assert_equal (10 , shiftwidth ())
325+ call assert_equal (10 , shiftwidth (1 ))
326+ call assert_equal (20 , shiftwidth (virtcol (' .' )))
327+ norm! $ >>
328+ let expect2 = [' x ' , ' ~ ' ]
329+ let lines = ScreenLines ([1 , 2 ], winwidth (0 ))
330+ call s: compare_lines (expect2, lines )
331+ call assert_equal (20 , shiftwidth (virtcol (' .' )-2 ))
332+ call assert_equal (30 , shiftwidth (virtcol (' .' )))
333+ norm! $ >>
334+ let expect3 = [' ' , ' x ' , ' ~ ' ]
335+ let lines = ScreenLines ([1 , 3 ], winwidth (0 ))
336+ call s: compare_lines (expect3, lines )
337+ call assert_equal (30 , shiftwidth (virtcol (' .' )-2 ))
338+ call assert_equal (40 , shiftwidth (virtcol (' .' )))
339+ norm! $ >>
340+ let expect4 = [' ' , ' ' , ' x ' ]
341+ let lines = ScreenLines ([1 , 3 ], winwidth (0 ))
342+ call assert_equal (40 , shiftwidth (virtcol (' .' )))
343+ call s: compare_lines (expect4, lines )
344+
345+ " Test 2: Put the cursor at the first column, result should be the same
346+ call setline (1 , " x" )
347+ norm! 0 >>
348+ let lines = ScreenLines (1 , winwidth (0 ))
349+ call s: compare_lines (expect1, lines )
350+ norm! 0 >>
351+ let lines = ScreenLines ([1 , 2 ], winwidth (0 ))
352+ call s: compare_lines (expect2, lines )
353+ norm! 0 >>
354+ let lines = ScreenLines ([1 , 3 ], winwidth (0 ))
355+ call s: compare_lines (expect3, lines )
356+ norm! 0 >>
357+ let lines = ScreenLines ([1 , 3 ], winwidth (0 ))
358+ call s: compare_lines (expect4, lines )
359+
360+ " cleanup
361+ bw !
362+ bw !
363+ endfunc
364+
300365func Test_vartabs_failures ()
301366 call assert_fails (' set vts=8,' )
302367 call assert_fails (' set vsts=8,' )
0 commit comments