2017-10-28 09:05:59 -07:00
|
|
|
" Test :retab
|
2022-11-29 19:04:50 -07:00
|
|
|
|
|
|
|
source check.vim
|
|
|
|
|
2017-10-28 09:05:59 -07:00
|
|
|
func SetUp()
|
|
|
|
new
|
|
|
|
call setline(1, "\ta \t b c ")
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func TearDown()
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Retab(bang, n)
|
|
|
|
let l:old_tabstop = &tabstop
|
|
|
|
let l:old_line = getline(1)
|
|
|
|
exe "retab" . a:bang . a:n
|
|
|
|
let l:line = getline(1)
|
|
|
|
call setline(1, l:old_line)
|
|
|
|
if a:n > 0
|
|
|
|
" :retab changes 'tabstop' to n with argument n > 0.
|
|
|
|
call assert_equal(a:n, &tabstop)
|
|
|
|
exe 'set tabstop=' . l:old_tabstop
|
|
|
|
else
|
|
|
|
" :retab does not change 'tabstop' with empty or n <= 0.
|
|
|
|
call assert_equal(l:old_tabstop, &tabstop)
|
|
|
|
endif
|
|
|
|
return l:line
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_retab()
|
|
|
|
set tabstop=8 noexpandtab
|
|
|
|
call assert_equal("\ta\t b c ", Retab('', ''))
|
|
|
|
call assert_equal("\ta\t b c ", Retab('', 0))
|
|
|
|
call assert_equal("\ta\t b c ", Retab('', 8))
|
|
|
|
call assert_equal("\ta\t b\t c\t ", Retab('!', ''))
|
|
|
|
call assert_equal("\ta\t b\t c\t ", Retab('!', 0))
|
|
|
|
call assert_equal("\ta\t b\t c\t ", Retab('!', 8))
|
|
|
|
|
|
|
|
call assert_equal("\t\ta\t\t\tb c ", Retab('', 4))
|
|
|
|
call assert_equal("\t\ta\t\t\tb\t\t c\t ", Retab('!', 4))
|
|
|
|
|
|
|
|
call assert_equal(" a\t\tb c ", Retab('', 10))
|
|
|
|
call assert_equal(" a\t\tb c ", Retab('!', 10))
|
|
|
|
|
|
|
|
set tabstop=8 expandtab
|
|
|
|
call assert_equal(" a b c ", Retab('', ''))
|
|
|
|
call assert_equal(" a b c ", Retab('', 0))
|
|
|
|
call assert_equal(" a b c ", Retab('', 8))
|
|
|
|
call assert_equal(" a b c ", Retab('!', ''))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 0))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 8))
|
|
|
|
|
|
|
|
call assert_equal(" a b c ", Retab(' ', 4))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 4))
|
|
|
|
|
|
|
|
call assert_equal(" a b c ", Retab(' ', 10))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 10))
|
|
|
|
|
|
|
|
set tabstop=4 noexpandtab
|
|
|
|
call assert_equal("\ta\t\tb c ", Retab('', ''))
|
|
|
|
call assert_equal("\ta\t\tb\t\t c\t ", Retab('!', ''))
|
|
|
|
call assert_equal("\t a\t\t\tb c ", Retab('', 3))
|
|
|
|
call assert_equal("\t a\t\t\tb\t\t\tc\t ", Retab('!', 3))
|
|
|
|
call assert_equal(" a\t b c ", Retab('', 5))
|
|
|
|
call assert_equal(" a\t b\t\t c\t ", Retab('!', 5))
|
|
|
|
|
|
|
|
set tabstop=4 expandtab
|
|
|
|
call assert_equal(" a b c ", Retab('', ''))
|
|
|
|
call assert_equal(" a b c ", Retab('!', ''))
|
|
|
|
call assert_equal(" a b c ", Retab('', 3))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 3))
|
|
|
|
call assert_equal(" a b c ", Retab('', 5))
|
|
|
|
call assert_equal(" a b c ", Retab('!', 5))
|
2022-02-12 11:23:38 -07:00
|
|
|
|
|
|
|
set tabstop& expandtab&
|
2017-10-28 09:05:59 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_retab_error()
|
|
|
|
call assert_fails('retab -1', 'E487:')
|
|
|
|
call assert_fails('retab! -1', 'E487:')
|
2022-01-06 02:54:33 -07:00
|
|
|
call assert_fails('ret -1000', 'E487:')
|
|
|
|
call assert_fails('ret 10000', 'E475:')
|
|
|
|
call assert_fails('ret 80000000000000000000', 'E475:')
|
2017-10-28 09:05:59 -07:00
|
|
|
endfunc
|
2022-02-12 11:23:38 -07:00
|
|
|
|
2022-11-29 18:48:10 -07:00
|
|
|
func RetabLoop()
|
|
|
|
while 1
|
|
|
|
set ts=4000
|
|
|
|
retab 4
|
|
|
|
endwhile
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_retab_endless()
|
2022-11-29 19:07:24 -07:00
|
|
|
" inside try/catch we can catch the error message
|
2022-02-12 11:23:38 -07:00
|
|
|
call setline(1, "\t0\t")
|
|
|
|
let caught = 'no'
|
|
|
|
try
|
2022-11-29 18:48:10 -07:00
|
|
|
call RetabLoop()
|
|
|
|
catch /E1240:/
|
2022-11-29 18:47:30 -07:00
|
|
|
let caught = v:exception
|
2022-02-12 11:23:38 -07:00
|
|
|
endtry
|
2022-11-29 18:48:10 -07:00
|
|
|
call assert_match('E1240:', caught)
|
2022-11-29 19:07:04 -07:00
|
|
|
|
2022-11-29 18:48:10 -07:00
|
|
|
set tabstop&
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_nocatch_retab_endless()
|
2022-11-29 19:07:24 -07:00
|
|
|
" when not inside try/catch an interrupt is generated to get out of loops
|
2022-11-29 18:48:10 -07:00
|
|
|
call setline(1, "\t0\t")
|
|
|
|
call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted'])
|
|
|
|
|
2022-02-12 11:23:38 -07:00
|
|
|
set tabstop&
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|