robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- 2-- Tests for default autocmds, mappings, commands, and menus. 3-- 4-- See options/defaults_spec.lua for default options and environment decisions. 5-- 6 7local t =require ( 'test.testutil' ) 8local n =require ( 'test.functional.testnvim' )() 9local Screen =require ( 'test.functional.ui.screen' ) 10 11local describe , it =t . describe , t . it 12describe ( 'default' , function () 13describe ( 'autocommands' , function () 14it ( 'nvim.terminal.TermClose closes terminal with default shell on success' , function () 15n . clear () 16n . api . nvim_set_option_value ( 'shell' , n . testprg ( 'shell-test' ), {} ) 17n . command ( 'set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=' ) 18 19-- Should not block other events 20n . command ( 'let g:n=0' ) 21n . command ( 'au BufEnter * let g:n = g:n + 1' ) 22 23t . eq ( 1 , n . exec_lua ( 'vim.cmd.terminal(); return vim.g.n' )) 24 25t . retry ( nil , 1000 , function () 26t . neq ( 'terminal' , n . api . nvim_get_option_value ( 'buftype' , { buf =0 } )) 27t . eq ( 2 , n . eval ( 'g:n' )) 28end ) 29end ) 30end ) 31 32describe ( 'popupmenu' , function () 33it ( 'can be disabled by user' , function () 34n . clear { 35args ={ '+autocmd! nvim.popupmenu' , '+aunmenu PopUp' } , 36} 37local screen =Screen . new ( 40 , 8 ) 38n . insert ( [[ 391 line 1 402 https://example.com 413 line 3 424 line 4]] ) 43 44n . api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 4 ) 45screen : expect ( { 46grid =[[ 471 line 1 | 482 ht^tps://example.com | 493 line 3 | 504 line 4 | 51{1:~ }|*3 52| 53]] , 54} ) 55end ) 56 57it ( 'right-click on URL shows "Open in web browser"' , function () 58n . clear () 59local screen =Screen . new ( 40 , 8 ) 60n . insert ( [[ 611 line 1 622 https://example.com 633 line 3 644 line 4]] ) 65 66n . api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 3 , 4 ) 67screen : expect ( { 68grid =[[ 691 line 1 | 702 https://example.com | 713 line 3 | 724 li^ne 4 | 73{1:~ }{4: Inspect }{1: }| 74{1:~ }{4: }{1: }| 75{1:~ }{4: Paste }{1: }| 76{4: Select All } | 77]] , 78} ) 79 80n . api . nvim_input_mouse ( 'right' , 'press' , '' , 0 , 1 , 4 ) 81screen : expect ( { 82grid =[[ 831 line 1 | 842 ht^tps://example.com | 853 l{4: Open in web browser } | 864 l{4: Inspect } | 87{1:~ }{4: }{1: }| 88{1:~ }{4: Paste }{1: }| 89{1:~ }{4: Select All }{1: }| 90{4: } | 91]] , 92} ) 93end ) 94end ) 95 96describe ( 'key mappings' , function () 97describe ( 'Visual mode search mappings' , function () 98it ( 'handle various chars properly' , function () 99n . clear ( { args_rm ={ '--cmd' } } ) 100local screen =Screen . new ( 60 , 8 ) 101screen : set_default_attr_ids ( { 102[ 1 ] ={ foreground =Screen . colors . NvimDarkGray4 } , 103[ 2 ] ={ 104foreground =Screen . colors . NvimLightGray2 , 105background =Screen . colors . NvimDarkGray4 , 106} , 107[ 3 ] ={ 108foreground =Screen . colors . NvimLightGrey1 , 109background =Screen . colors . NvimDarkYellow , 110} , 111[ 4 ] ={ 112foreground =Screen . colors . NvimDarkGrey1 , 113background =Screen . colors . NvimLightYellow , 114} , 115} ) 116n . api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 117[[testing <CR> /?\!1]] , 118[[testing <CR> /?\!2]] , 119[[testing <CR> /?\!3]] , 120[[testing <CR> /?\!4]] , 121} ) 122n . feed ( 'gg0vf!' ) 123n . poke_eventloop () 124n . feed ( '*' ) 125screen : expect ( [[ 126{3:testing <CR> /?\!}1 | 127{4:^testing <CR> /?\!}2 | 128{3:testing <CR> /?\!}3 | 129{3:testing <CR> /?\!}4 | 130{1:~ }|*2 131{2:[No Name] [+] 2,1 All}| 132/\Vtesting <CR> /?\\! [2/4] | 133]] ) 134n . feed ( 'n' ) 135screen : expect ( [[ 136{3:testing <CR> /?\!}1 | 137{3:testing <CR> /?\!}2 | 138{4:^testing <CR> /?\!}3 | 139{3:testing <CR> /?\!}4 | 140{1:~ }|*2 141{2:[No Name] [+] 3,1 All}| 142/\Vtesting <CR> /?\\! [3/4] | 143]] ) 144n . feed ( 'G0vf!' ) 145n . poke_eventloop () 146n . feed ( '#' ) 147screen : expect ( [[ 148{3:testing <CR> /?\!}1 | 149{3:testing <CR> /?\!}2 | 150{4:^testing <CR> /?\!}3 | 151{3:testing <CR> /?\!}4 | 152{1:~ }|*2 153{2:[No Name] [+] 3,1 All}| 154?\Vtesting <CR> /?\\! [3/4] | 155]] ) 156n . feed ( 'n' ) 157screen : expect ( [[ 158{3:testing <CR> /?\!}1 | 159{4:^testing <CR> /?\!}2 | 160{3:testing <CR> /?\!}3 | 161{3:testing <CR> /?\!}4 | 162{1:~ }|*2 163{2:[No Name] [+] 2,1 All}| 164?\Vtesting <CR> /?\\! [2/4] | 165]] ) 166end ) 167end ) 168 169describe ( 'unimpaired-style mappings' , function () 170it ( 'show the command output when successful' , function () 171n . clear ( { args_rm ={ '--cmd' } } ) 172local screen =Screen . new ( 40 , 8 ) 173n . fn . setqflist ( { 174{ filename ='file1' , text ='item1' } , 175{ filename ='file2' , text ='item2' } , 176} ) 177 178n . feed ( ']q' ) 179 180screen : set_default_attr_ids ( { 181[ 1 ] ={ foreground =Screen . colors . NvimDarkGrey4 } , 182[ 2 ] ={ 183background =Screen . colors . NvimDarkGrey4 , 184foreground =Screen . colors . NvimLightGray2 , 185} , 186} ) 187screen : expect ( { 188grid =[[ 189^ | 190{1:~ }|*5 191{2:file2 0,0-1 All}| 192(2 of 2): item2 | 193]] , 194} ) 195end ) 196 197it ( 'do not show a full stack trace when unsuccessful #30625' , function () 198n . clear ( { args_rm ={ '--cmd' } } ) 199local screen =Screen . new ( 40 , 8 ) 200screen : set_default_attr_ids ( { 201[ 1 ] ={ foreground =Screen . colors . NvimDarkGray4 } , 202[ 2 ] ={ 203background =Screen . colors . NvimDarkGray4 , 204foreground =Screen . colors . NvimLightGrey2 , 205} , 206[ 3 ] ={ foreground =Screen . colors . NvimLightRed } , 207[ 4 ] ={ foreground =Screen . colors . NvimLightCyan } , 208} ) 209 210n . feed ( '[a' ) 211screen : expect ( { 212grid =[[ 213| 214{1:~ }|*4 215{2: }| 216{3:E163: There is only one file to edit} | 217{4:Press ENTER or type command to continue}^ | 218]] , 219} ) 220 221n . feed ( '[q' ) 222screen : expect ( { 223grid =[[ 224^ | 225{1:~ }|*5 226{2:[No Name] 0,0-1 All}| 227{3:E42: No Errors} | 228]] , 229} ) 230 231n . feed ( '[l' ) 232screen : expect ( { 233grid =[[ 234^ | 235{1:~ }|*5 236{2:[No Name] 0,0-1 All}| 237{3:E776: No location list} | 238]] , 239} ) 240 241n . feed ( '[t' ) 242screen : expect ( { 243grid =[[ 244^ | 245{1:~ }|*5 246{2:[No Name] 0,0-1 All}| 247{3:E73: Tag stack empty} | 248]] , 249} ) 250end ) 251 252describe ( '[<Space>' , function () 253it ( 'adds an empty line above the current line' , function () 254n . clear ( { args_rm ={ '--cmd' } } ) 255n . insert ( [[first line]] ) 256n . feed ( '[<Space>' ) 257n . expect ( [[ 258 259first line]] ) 260end ) 261 262it ( 'works with a count' , function () 263n . clear ( { args_rm ={ '--cmd' } } ) 264n . insert ( [[first line]] ) 265n . feed ( '5[<Space>' ) 266n . expect ( [[ 267 268 269 270 271 272first line]] ) 273end ) 274 275it ( 'supports dot repetition' , function () 276n . clear ( { args_rm ={ '--cmd' } } ) 277n . insert ( [[first line]] ) 278n . feed ( '[<Space>' ) 279n . feed ( '.' ) 280n . expect ( [[ 281 282 283first line]] ) 284end ) 285 286it ( 'supports dot repetition and a count' , function () 287n . clear ( { args_rm ={ '--cmd' } } ) 288n . insert ( [[first line]] ) 289n . feed ( '[<Space>' ) 290n . feed ( '3.' ) 291n . expect ( [[ 292 293 294 295 296first line]] ) 297end ) 298end ) 299 300describe ( ']<Space>' , function () 301it ( 'adds an empty line below the current line' , function () 302n . clear ( { args_rm ={ '--cmd' } } ) 303n . insert ( [[first line]] ) 304n . feed ( ']<Space>' ) 305n . expect ( [[ 306first line 307]] ) 308end ) 309 310it ( 'works with a count' , function () 311n . clear ( { args_rm ={ '--cmd' } } ) 312n . insert ( [[first line]] ) 313n . feed ( '5]<Space>' ) 314n . expect ( [[ 315first line 316 317 318 319 320]] ) 321end ) 322 323it ( 'supports dot repetition' , function () 324n . clear ( { args_rm ={ '--cmd' } } ) 325n . insert ( [[first line]] ) 326n . feed ( ']<Space>' ) 327n . feed ( '.' ) 328n . expect ( [[ 329first line 330 331]] ) 332end ) 333 334it ( 'supports dot repetition and a count' , function () 335n . clear ( { args_rm ={ '--cmd' } } ) 336n . insert ( [[first line]] ) 337n . feed ( ']<Space>' ) 338n . feed ( '2.' ) 339n . expect ( [[ 340first line 341 342 343]] ) 344end ) 345end ) 346end ) 347end ) 348end )