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