" Test for breakindent
"
" Note: if you get strange failures when adding new tests, it might be that
" while the test is run, the breakindent caching gets in its way.
" It helps to change the tabstop setting and force a redraw (e.g. see
" Test_breakindent08())
source check.vim
CheckOption breakindent
source view_util.vim
source screendump.vim
func SetUp()
let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
endfunc
func s:screen_lines(lnum, width) abort
return ScreenLines([a:lnum, a:lnum + 2], a:width)
endfunc
func s:screen_lines2(lnums, lnume, width) abort
return ScreenLines([a:lnums, a:lnume], a:width)
endfunc
func s:compare_lines(expect, actual)
call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
endfunc
func s:test_windows(...)
call NewWindow(10, 20)
setl ts=4 sw=4 sts=4 breakindent
put =s:input
exe get(a:000, 0, '')
endfunc
func s:close_windows(...)
call CloseWindow()
exe get(a:000, 0, '')
endfunc
func Test_breakindent01()
" simple breakindent test
call s:test_windows('setl briopt=min:0')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " qrst",
\ " GHIJ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_breakindent01_vartabs()
" like 01 but with vartabs feature
CheckFeature vartabs
call s:test_windows('setl briopt=min:0 vts=4')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " qrst",
\ " GHIJ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows('set vts&')
endfunc
func Test_breakindent02()
" simple breakindent test with showbreak set
set sbr=>>
call s:test_windows('setl briopt=min:0 sbr=')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " >>qr",
\ " >>EF",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows('set sbr=')
endfunc
func Test_breakindent02_vartabs()
CheckFeature vartabs
" simple breakindent test with showbreak set
call s:test_windows('setl briopt=min:0 sbr=>> vts=4')
let lines = s:screen_lines(line('.'), 8)
let expect = [
\ " abcd",
\ " >>qr",
\ " >>EF",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows('set sbr= vts&')
endfunc
func Test_breakindent03()
" simple breakindent test with showbreak set and briopt including sbr
call s:test_windows('setl briopt=sbr,min:0 sbr=++')
let lines = s:screen_lines(line('.'), 8)
let expect = [
\ " abcd",
\ "++ qrst",
\ "++ GHIJ",
\ ]
call s:compare_lines(expect, lines)
" clean up
call s:close_windows('set sbr=')
endfunc
func Test_breakindent03_vartabs()
" simple breakindent test with showbreak set and briopt including sbr
CheckFeature vartabs
call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4')
let lines = s:screen_lines(line('.'), 8)
let expect = [
\ " abcd",
\ "++ qrst",
\ "++ GHIJ",
\ ]
call s:compare_lines(expect, lines)
" clean up
call s:close_windows('set sbr= vts&')
endfunc
func Test_breakindent04()
" breakindent set with min width 18
set sbr=<<<
call s:test_windows('setl sbr=NONE briopt=min:18')
let lines = s:screen_lines(line('.'), 8)
let expect = [
\ " abcd",
\ " qrstuv",
\ " IJKLMN",
\ ]
call s:compare_lines(expect, lines)
" clean up
call s:close_windows('set sbr=')
set sbr=
endfunc
func Test_breakindent04_vartabs()
" breakindent set with min width 18
CheckFeature vartabs
call s:test_windows('setl sbr= briopt=min:18 vts=4')
let lines = s:screen_lines(line('.'), 8)
let expect = [
\ " abcd",
\ " qrstuv",
\ " IJKLMN",
\ ]
call s:compare_lines(expect, lines)
" clean up
call s:close_windows('set sbr= vts&')
endfunc
func Test_breakindent05()
" breakindent set and shift by 2
call s:test_windows('setl briopt=shift:2,min:0')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " qr",
\ " EF",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_breakindent05_vartabs()
" breakindent set and shift by 2
CheckFeature vartabs
call s:test_windows('setl briopt=shift:2,min:0 vts=4')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " qr",
\ " EF",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows('set vts&')
endfunc
func Test_breakindent06()
" breakindent set and shift by -1
call s:test_windows('setl briopt=shift:-1,min:0')
let lines = s:screen_lines(line('.'),8)
let expect = [
\ " abcd",
\ " qrstu",
\ " HIJKL",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_breakindent06_vartabs()
" breakindent set and shift by -1
CheckFeature vartabs
call s:test_windows('setl briopt=shift:-1,min:0 vts=4')
let lines = s:screen_lines(line('.'),8)
let expect =