test_command_count.vim 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. " Test for user command counts.
  2. func Test_command_count_0()
  3. let bufnr = bufnr('%')
  4. set hidden
  5. set noswapfile
  6. split DoesNotExistEver
  7. let lastbuf = bufnr('$')
  8. call setline(1, 'asdf')
  9. quit!
  10. command! -range -addr=loaded_buffers RangeLoadedBuffers :let lines = [<line1>, <line2>]
  11. command! -range=% -addr=loaded_buffers RangeLoadedBuffersAll :let lines = [<line1>, <line2>]
  12. command! -range -addr=buffers RangeBuffers :let lines = [<line1>, <line2>]
  13. command! -range=% -addr=buffers RangeBuffersAll :let lines = [<line1>, <line2>]
  14. .,$RangeLoadedBuffers
  15. call assert_equal([bufnr, bufnr], lines)
  16. %RangeLoadedBuffers
  17. call assert_equal([bufnr, bufnr], lines)
  18. RangeLoadedBuffersAll
  19. call assert_equal([bufnr, bufnr], lines)
  20. .,$RangeBuffers
  21. call assert_equal([bufnr, lastbuf], lines)
  22. %RangeBuffers
  23. call assert_equal([bufnr, lastbuf], lines)
  24. RangeBuffersAll
  25. call assert_equal([bufnr, lastbuf], lines)
  26. delcommand RangeLoadedBuffers
  27. delcommand RangeLoadedBuffersAll
  28. delcommand RangeBuffers
  29. delcommand RangeBuffersAll
  30. set hidden&
  31. set swapfile&
  32. endfunc
  33. func Test_command_count_1()
  34. silent! %argd
  35. arga a b c d e
  36. argdo echo "loading buffers"
  37. argu 3
  38. command! -range -addr=arguments RangeArguments :let lines = [<line1>, <line2>]
  39. command! -range=% -addr=arguments RangeArgumentsAll :let lines = [<line1>, <line2>]
  40. .-,$-RangeArguments
  41. call assert_equal([2, 4], lines)
  42. %RangeArguments
  43. call assert_equal([1, 5], lines)
  44. RangeArgumentsAll
  45. call assert_equal([1, 5], lines)
  46. N
  47. .RangeArguments
  48. call assert_equal([2, 2], lines)
  49. delcommand RangeArguments
  50. delcommand RangeArgumentsAll
  51. split|split|split|split
  52. 3wincmd w
  53. command! -range -addr=windows RangeWindows :let lines = [<line1>, <line2>]
  54. .,$RangeWindows
  55. call assert_equal([3, 5], lines)
  56. %RangeWindows
  57. call assert_equal([1, 5], lines)
  58. delcommand RangeWindows
  59. command! -range=% -addr=windows RangeWindowsAll :let lines = [<line1>, <line2>]
  60. RangeWindowsAll
  61. call assert_equal([1, 5], lines)
  62. delcommand RangeWindowsAll
  63. only
  64. blast|bd
  65. tabe|tabe|tabe|tabe
  66. normal 2gt
  67. command! -range -addr=tabs RangeTabs :let lines = [<line1>, <line2>]
  68. .,$RangeTabs
  69. call assert_equal([2, 5], lines)
  70. %RangeTabs
  71. call assert_equal([1, 5], lines)
  72. delcommand RangeTabs
  73. command! -range=% -addr=tabs RangeTabsAll :let lines = [<line1>, <line2>]
  74. RangeTabsAll
  75. call assert_equal([1, 5], lines)
  76. delcommand RangeTabsAll
  77. 1tabonly
  78. s/\n/\r\r\r\r\r/
  79. 2ma<
  80. $-ma>
  81. command! -range=% RangeLines :let lines = [<line1>, <line2>]
  82. '<,'>RangeLines
  83. call assert_equal([2, 5], lines)
  84. delcommand RangeLines
  85. command! -range=% -buffer LocalRangeLines :let lines = [<line1>, <line2>]
  86. '<,'>LocalRangeLines
  87. call assert_equal([2, 5], lines)
  88. delcommand LocalRangeLines
  89. endfunc
  90. func Test_command_count_2()
  91. silent! %argd
  92. arga a b c d
  93. call assert_fails('5argu', 'E16:')
  94. $argu
  95. call assert_equal('d', expand('%:t'))
  96. 1argu
  97. call assert_equal('a', expand('%:t'))
  98. call assert_fails('300b', 'E16:')
  99. split|split|split|split
  100. 0close
  101. $wincmd w
  102. $close
  103. call assert_equal(3, winnr())
  104. call assert_fails('$+close', 'E16:')
  105. $tabe
  106. call assert_equal(2, tabpagenr())
  107. call assert_fails('$+tabe', 'E16:')
  108. only!
  109. e x
  110. 0tabm
  111. normal 1gt
  112. call assert_equal('x', expand('%:t'))
  113. tabonly!
  114. only!
  115. endfunc
  116. func Test_command_count_3()
  117. let bufnr = bufnr('%')
  118. se nohidden
  119. e aaa
  120. let buf_aaa = bufnr('%')
  121. e bbb
  122. let buf_bbb = bufnr('%')
  123. e ccc
  124. let buf_ccc = bufnr('%')
  125. exe bufnr . 'buf'
  126. call assert_equal([1, 1, 1], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)])
  127. exe buf_bbb . "," . buf_ccc . "bdelete"
  128. call assert_equal([1, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)])
  129. exe buf_aaa . "bdelete"
  130. call assert_equal([0, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)])
  131. endfunc
  132. func Test_command_count_4()
  133. %argd
  134. let bufnr = bufnr('$')
  135. next aa bb cc dd ee ff
  136. call assert_equal(bufnr, bufnr('%'))
  137. 3argu
  138. let args = []
  139. .,$-argdo call add(args, expand('%'))
  140. call assert_equal(['cc', 'dd', 'ee'], args)
  141. " create windows to get 5
  142. split|split|split|split
  143. 2wincmd w
  144. let windows = []
  145. .,$-windo call add(windows, winnr())
  146. call assert_equal([2, 3, 4], windows)
  147. only!
  148. exe bufnr . 'buf'
  149. let bufnr = bufnr('%')
  150. let buffers = []
  151. .,$-bufdo call add(buffers, bufnr('%'))
  152. call assert_equal([bufnr, bufnr + 1, bufnr + 2, bufnr + 3, bufnr + 4], buffers)
  153. exe (bufnr + 3) . 'bdel'
  154. let buffers = []
  155. exe (bufnr + 2) . ',' . (bufnr + 5) . "bufdo call add(buffers, bufnr('%'))"
  156. call assert_equal([bufnr + 2, bufnr + 4, bufnr + 5], buffers)
  157. " create tabpages to get 5
  158. tabe|tabe|tabe|tabe
  159. normal! 2gt
  160. let tabpages = []
  161. .,$-tabdo call add(tabpages, tabpagenr())
  162. call assert_equal([2, 3, 4], tabpages)
  163. tabonly!
  164. bwipe!
  165. endfunc