test_retab.vim 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. " Test :retab
  2. source check.vim
  3. func SetUp()
  4. new
  5. call setline(1, "\ta \t b c ")
  6. endfunc
  7. func TearDown()
  8. bwipe!
  9. endfunc
  10. func Retab(bang, n)
  11. let l:old_tabstop = &tabstop
  12. let l:old_line = getline(1)
  13. exe "retab" . a:bang . a:n
  14. let l:line = getline(1)
  15. call setline(1, l:old_line)
  16. if a:n > 0
  17. " :retab changes 'tabstop' to n with argument n > 0.
  18. call assert_equal(a:n, &tabstop)
  19. exe 'set tabstop=' . l:old_tabstop
  20. else
  21. " :retab does not change 'tabstop' with empty or n <= 0.
  22. call assert_equal(l:old_tabstop, &tabstop)
  23. endif
  24. return l:line
  25. endfunc
  26. func Test_retab()
  27. set tabstop=8 noexpandtab
  28. call assert_equal("\ta\t b c ", Retab('', ''))
  29. call assert_equal("\ta\t b c ", Retab('', 0))
  30. call assert_equal("\ta\t b c ", Retab('', 8))
  31. call assert_equal("\ta\t b\t c\t ", Retab('!', ''))
  32. call assert_equal("\ta\t b\t c\t ", Retab('!', 0))
  33. call assert_equal("\ta\t b\t c\t ", Retab('!', 8))
  34. call assert_equal("\t\ta\t\t\tb c ", Retab('', 4))
  35. call assert_equal("\t\ta\t\t\tb\t\t c\t ", Retab('!', 4))
  36. call assert_equal(" a\t\tb c ", Retab('', 10))
  37. call assert_equal(" a\t\tb c ", Retab('!', 10))
  38. set tabstop=8 expandtab
  39. call assert_equal(" a b c ", Retab('', ''))
  40. call assert_equal(" a b c ", Retab('', 0))
  41. call assert_equal(" a b c ", Retab('', 8))
  42. call assert_equal(" a b c ", Retab('!', ''))
  43. call assert_equal(" a b c ", Retab('!', 0))
  44. call assert_equal(" a b c ", Retab('!', 8))
  45. call assert_equal(" a b c ", Retab(' ', 4))
  46. call assert_equal(" a b c ", Retab('!', 4))
  47. call assert_equal(" a b c ", Retab(' ', 10))
  48. call assert_equal(" a b c ", Retab('!', 10))
  49. set tabstop=4 noexpandtab
  50. call assert_equal("\ta\t\tb c ", Retab('', ''))
  51. call assert_equal("\ta\t\tb\t\t c\t ", Retab('!', ''))
  52. call assert_equal("\t a\t\t\tb c ", Retab('', 3))
  53. call assert_equal("\t a\t\t\tb\t\t\tc\t ", Retab('!', 3))
  54. call assert_equal(" a\t b c ", Retab('', 5))
  55. call assert_equal(" a\t b\t\t c\t ", Retab('!', 5))
  56. set tabstop=4 expandtab
  57. call assert_equal(" a b c ", Retab('', ''))
  58. call assert_equal(" a b c ", Retab('!', ''))
  59. call assert_equal(" a b c ", Retab('', 3))
  60. call assert_equal(" a b c ", Retab('!', 3))
  61. call assert_equal(" a b c ", Retab('', 5))
  62. call assert_equal(" a b c ", Retab('!', 5))
  63. set tabstop& expandtab&
  64. endfunc
  65. func Test_retab_error()
  66. call assert_fails('retab -1', 'E487:')
  67. call assert_fails('retab! -1', 'E487:')
  68. call assert_fails('ret -1000', 'E487:')
  69. call assert_fails('ret 10000', 'E475:')
  70. call assert_fails('ret 80000000000000000000', 'E475:')
  71. endfunc
  72. func RetabLoop()
  73. while 1
  74. set ts=4000
  75. retab 4
  76. endwhile
  77. endfunc
  78. func Test_retab_endless()
  79. " inside try/catch we can catch the error message
  80. call setline(1, "\t0\t")
  81. let caught = 'no'
  82. try
  83. call RetabLoop()
  84. catch /E1240:/
  85. let caught = v:exception
  86. endtry
  87. call assert_match('E1240:', caught)
  88. set tabstop&
  89. endfunc
  90. func Test_nocatch_retab_endless()
  91. " when not inside try/catch an interrupt is generated to get out of loops
  92. call setline(1, "\t0\t")
  93. call assert_fails('call RetabLoop()', ['E1240:', 'Interrupted'])
  94. set tabstop&
  95. endfunc
  96. " vim: shiftwidth=2 sts=2 expandtab