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