test_tab.vim 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. " Various tests for inserting a Tab.
  2. " Tests for "r<Tab>" with 'smarttab' and 'expandtab' set/not set.
  3. " Also test that dv_ works correctly
  4. func Test_smarttab()
  5. enew!
  6. set smarttab expandtab ts=8 sw=4
  7. " make sure that backspace works, no matter what termcap is used
  8. exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08"
  9. call append(0, ['start text',
  10. \ "\t\tsome test text",
  11. \ 'test text',
  12. \ "\t\tother test text",
  13. \ ' a cde',
  14. \ ' f ghi',
  15. \ 'test text',
  16. \ ' Second line beginning with whitespace'
  17. \ ])
  18. call cursor(1, 1)
  19. exe "normal /some\<CR>"
  20. exe "normal r\t"
  21. call assert_equal("\t\t ome test text", getline('.'))
  22. set noexpandtab
  23. exe "normal /other\<CR>"
  24. exe "normal r\t"
  25. call assert_equal("\t\t ther test text", getline('.'))
  26. " Test replacing with Tabs and then backspacing to undo it
  27. exe "normal j0wR\t\t\t\<BS>\<BS>\<BS>"
  28. call assert_equal(" a cde", getline('.'))
  29. " Test replacing with Tabs
  30. exe "normal j0wR\t\t\t"
  31. call assert_equal(" \t\thi", getline('.'))
  32. " Test that copyindent works with expandtab set
  33. set expandtab smartindent copyindent ts=8 sw=8 sts=8
  34. exe "normal jo{\<CR>x"
  35. call assert_equal('{', getline(line('.') - 1))
  36. call assert_equal(' x', getline('.'))
  37. set nosol
  38. exe "normal /Second line/\<CR>"
  39. exe "normal fwdv_"
  40. call assert_equal(' with whitespace', getline('.'))
  41. enew!
  42. set expandtab& smartindent& copyindent& ts& sw& sts&
  43. endfunc
  44. func Test_softtabstop()
  45. new
  46. set sts=0 sw=0
  47. exe "normal ix\<Tab>x\<Esc>"
  48. call assert_equal("x\tx", getline(1))
  49. call setline(1, '')
  50. set sts=4
  51. exe "normal ix\<Tab>x\<Esc>"
  52. call assert_equal("x x", getline(1))
  53. call setline(1, '')
  54. set sts=-1 sw=4
  55. exe "normal ix\<Tab>x\<Esc>"
  56. call assert_equal("x x", getline(1))
  57. call setline(1, 'x ')
  58. set sts=0 sw=0 backspace=start
  59. exe "normal A\<BS>x\<Esc>"
  60. call assert_equal("x x", getline(1))
  61. call setline(1, 'x ')
  62. set sts=4
  63. exe "normal A\<BS>x\<Esc>"
  64. call assert_equal("x x", getline(1))
  65. call setline(1, 'x ')
  66. set sts=-1 sw=4
  67. exe "normal A\<BS>x\<Esc>"
  68. call assert_equal("x x", getline(1))
  69. call setline(1, 'x')
  70. set sts=-1 sw=0 smarttab
  71. exe "normal I\<Tab>\<Esc>"
  72. call assert_equal("\tx", getline(1))
  73. call setline(1, 'x')
  74. exe "normal I\<Tab>\<BS>\<Esc>"
  75. call assert_equal("x", getline(1))
  76. set sts=0 sw=0 backspace& nosmarttab
  77. bwipe!
  78. endfunc