robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
50c50ab119
master
1-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI. 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local clear , exec , exec_lua , feed =n . clear , n . exec , n . exec_lua , n . feed 9 10describe ( 'cmdline2' , function () 11local screen 12before_each ( function () 13clear () 14screen =Screen . new () 15screen : add_extra_attr_ids ( { 16[ 100 ] ={ foreground =Screen . colors . Magenta1 , bold =true } , 17[ 101 ] ={ background =Screen . colors . Yellow , foreground =Screen . colors . Grey0 } , 18[ 102 ] ={ background =Screen . colors . Cyan1 , foreground =Screen . colors . SlateBlue } , 19} ) 20exec_lua ( function () 21require ( 'vim._core.ui2' ). enable ( {} ) 22end ) 23end ) 24 25it ( "no crash for invalid grid after 'cmdheight' OptionSet" , function () 26exec ( 'tabnew | tabprev' ) 27feed ( ':set ch=0' ) 28screen : expect ( [[ 29{5: [No Name] }{24: [No Name] }{2: }{24:X}| 30| 31{1:~ }|*11 32{16::}{15:set} {16:ch}{15:=}0^ | 33]] ) 34feed ( '<CR>' ) 35exec ( 'tabnext' ) 36screen : expect ( [[ 37{24: [No Name] }{5: [No Name] }{2: }{24:X}| 38^ | 39{1:~ }|*11 40{16::}{15:set} {16:ch}{15:=}0 | 41]] ) 42exec ( 'tabnext' ) 43screen : expect ( [[ 44{5: [No Name] }{24: [No Name] }{2: }{24:X}| 45^ | 46{1:~ }|*12 47]] ) 48n . assert_alive () 49end ) 50 51it ( "redraw does not clear 'incsearch' highlight with conceal" , function () 52exec ( 'call setline(1, ["foo", "foobar"]) | set conceallevel=1 concealcursor=c' ) 53feed ( '/foo' ) 54screen : expect ( [[ 55{10:foo} | 56{2:foo}bar | 57{1:~ }|*11 58/foo^ | 59]] ) 60end ) 61 62it ( 'block mode' , function () 63feed ( ':if 1<CR>' ) 64screen : expect ( [[ 65| 66{1:~ }|*11 67{16::}{15:if} {26:1} | 68{16::} ^ | 69]] ) 70feed ( 'echo "foo"' ) 71screen : expect ( [[ 72| 73{1:~ }|*11 74{16::}{15:if} {26:1} | 75{16::} {15:echo} {26:"foo"}^ | 76]] ) 77feed ( '<CR>' ) 78screen : expect ( [[ 79| 80{1:~ }|*9 81{16::}{15:if} {26:1} | 82{16::} {15:echo} {26:"foo"} | 83foo | 84{16::} ^ | 85]] ) 86feed ( [[echo input("foo\nbar:")<CR>]] ) 87screen : expect ( [[ 88| 89{1:~ }|*7 90{16::}{15:if} {26:1} | 91{16::} {15:echo} {26:"foo"} | 92foo | 93{16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 94foo | 95bar:^ | 96]] ) 97feed ( 'baz' ) 98screen : expect ( [[ 99| 100{1:~ }|*7 101{16::}{15:if} {26:1} | 102{16::} {15:echo} {26:"foo"} | 103foo | 104{16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 105foo | 106bar:baz^ | 107]] ) 108feed ( '<CR>' ) 109screen : expect ( [[ 110| 111{1:~ }|*5 112{16::}{15:if} {26:1} | 113{16::} {15:echo} {26:"foo"} | 114foo | 115{16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 116foo | 117bar:baz | 118baz | 119{16::} ^ | 120]] ) 121feed ( 'endif' ) 122screen : expect ( [[ 123| 124{1:~ }|*5 125{16::}{15:if} {26:1} | 126{16::} {15:echo} {26:"foo"} | 127foo | 128{16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 129foo | 130bar:baz | 131baz | 132{16::} {15:endif}^ | 133]] ) 134feed ( '<CR>' ) 135screen : expect ( [[ 136^ | 137{1:~ }|*12 138| 139]] ) 140end ) 141 142it ( 'handles empty prompt' , function () 143feed ( ":call input('')<CR>" ) 144screen : expect ( [[ 145| 146{1:~ }|*12 147^ | 148]] ) 149-- Message moved to dialog with empty prompt 150feed ( "<CR>:echo 'foo' | call input('')<CR>" ) 151screen : expect ( [[ 152| 153{1:~ }|*10 154{3: }| 155foo | 156^ | 157]] ) 158end ) 159 160it ( 'highlights after deleting buffer' , function () 161feed ( ':sil %bw!<CR>:call foo()' ) 162screen : expect ( [[ 163| 164{1:~ }|*12 165{16::}{15:call} {25:foo}{16:()}^ | 166]] ) 167end ) 168 169it ( 'can change cmdline buffer during textlock' , function () 170exec ( [[ 171func Foo(a, b) 172redrawstatus! 173endfunc 174set wildoptions=pum findfunc=Foo wildmode=noselect:lastused,full 175au CmdlineChanged * call wildtrigger() 176]] ) 177feed ( ':find ' ) 178screen : expect ( [[ 179| 180{1:~ }|*12 181{16::}{15:find} ^ | 182]] ) 183t . eq ( "E1514: 'findfunc' did not return a List type" , n . eval ( 'v:errmsg' )) 184end ) 185 186it ( 'substitution match, empty message does not clear active cmdline' , function () 187exec ( 'call setline(1, "foo")' ) 188feed ( ':s/f' ) 189screen : expect ( [[ 190{10:f}oo | 191{1:~ }|*12 192{16::}{15:s}{16:/f^ } | 193]] ) 194feed ( '<Esc>:foo' ) 195screen : expect ( [[ 196foo | 197{1:~ }|*12 198{16::}{15:foo}^ | 199]] ) 200exec ( 'echo' ) 201screen : expect_unchanged ( true ) 202end ) 203 204it ( 'keeps the confirmation match highlighted with nohlsearch #41039' , function () 205exec ( 'call setline(1, "test test") | set nohlsearch' ) 206feed ( '/te<CR>' ) 207screen : expect ( [[ 208test ^test | 209{1:~ }|*12 210/te | 211]] ) 212 213feed ( ':%s/te/t/gc<CR>' ) 214screen : expect ( [[ 215{2:te}st test | 216{1:~ }|*11 217{6:replace with t? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll}| 218{6: up(^E)/down(^Y)}^ | 219]] ) 220end ) 221 222it ( 'dialog position is adjusted for toggled non-pum wildmenu' , function () 223exec ( [[ 224set wildmode=list:full,full wildoptions-=pum 225func Foo() 226endf 227func Fooo() 228endf 229]] ) 230feed ( ':call Fo<C-Z>' ) 231screen : expect ( [[ 232| 233{1:~ }|*8 234{3: }| 235Foo() Fooo() | 236| 237{101:Foo()}{3: Fooo() }| 238{16::}{15:call} {25:Foo}{16:()}^ | 239]] ) 240feed ( '<BS><BS>' ) 241exec ( 'set wildoptions+=pum laststatus=2' ) 242screen : expect ( [[ 243| 244{1:~ }|*9 245{3: }| 246Foo() Fooo() | 247| 248{16::}{15:call} Foo^ | 249]] ) 250feed ( '<C-Z>' ) 251screen : expect ( [[ 252| 253{1:~ }|*9 254{3: }| 255Foo(){12: Foo() } | 256{4: Fooo() } | 257{16::}{15:call} {25:Foo}{16:()}^ | 258]] ) 259end ) 260 261it ( 'updated after setcmdline() #38764' , function () 262-- Also check that command-preview is updated. 263exec ( 'call setline(1, "foo")' ) 264feed ( ':%s/foo' ) 265screen : expect ( [[ 266{10:foo} | 267{1:~ }|*12 268{16::}%{15:s}{16:/foo^ } | 269]] ) 270exec_lua ( function () 271_G . events ={} 272vim . api . nvim_create_autocmd ( { 'CmdlineChanged' , 'CursorMovedC' } , { 273callback =function ( ev ) 274_G . events [ ev . event ] =( _G . events [ ev . event ] or 0 ) + 1 275end , 276} ) 277end ) 278exec ( 'call setcmdline("%s/fo")' ) 279screen : expect ( [[ 280{10:fo}o | 281{1:~ }|*12 282{16::}%{15:s}{16:/fo^ } | 283]] ) 284t . eq ( { CmdlineChanged =1 , CursorMovedC =1 } , exec_lua ( 'return _G.events' )) 285end ) 286 287it ( "no 'incsearch' recursion with 'verbose' regex message" , function () 288exec ( 'set verbose=1' ) 289feed ( [[:%s/.\{//}]] ) 290screen : expect ( [[ 291| 292{1:~ }|*9 293{3: }| 294Switching to backtracking RE engine for pattern: .\{ |*2 295{16::}%{15:s}{16:/.\{//}^ } | 296]] ) 297end ) 298 299it ( 'is empty after backspace' , function () 300feed ( ':' ) 301screen : expect ( [[ 302| 303{1:~ }|*12 304{16::}^ | 305]] ) 306 307feed ( '<BS>' ) 308screen : expect ( [[ 309^ | 310{1:~ }|*12 311| 312]] ) 313end ) 314 315it ( 'matchparen highlights' , function () 316exec ( 'source $VIMRUNTIME/plugin/matchparen.lua' ) 317feed ( ':call foo(bar())' ) 318screen : expect ( [[ 319| 320{1:~ }|*12 321{16::}{15:call} {25:foo}{102:(}{25:bar}{16:()}{102:)}^ | 322]] ) 323feed ( '<Left>' ) 324screen : expect ( [[ 325| 326{1:~ }|*12 327{16::}{15:call} {25:foo}{16:(}{25:bar}{102:()}{16:^)} | 328]] ) 329feed ( '<Right><BS><BS>' ) 330screen : expect ( [[ 331| 332{1:~ }|*12 333{16::}{15:call} {25:foo}{16:(}{25:bar}{16:(}^ | 334]] ) 335end ) 336 337it ( "doesn't interfere with :$q" , function () 338exec ( 'split b' ) 339exec ( 'wincmd J' ) 340exec ( 'wincmd p' ) 341exec ( '$q' ) -- this would close a ui2 window, not the second visible window 342 343local nwins =vim . fn . winnr ( '$' ) 344assert ( nwins == 1 ) 345end ) 346end ) 347 348describe ( 'cmdline2' , function () 349it ( 'resizing during startup shows confirm prompt #36439' , function () 350clear ( { 351args ={ 352'--clean' , 353'+lua require("vim._core.ui2").enable({})' , 354"+call feedkeys(':')" , 355} , 356} ) 357local screen =Screen . new () 358feed ( 'call confirm("Ok?")<CR>' ) 359screen : try_resize ( screen . _width + 1 , screen . _height ) 360screen : expect ( [[ 361|*10 362{3: }| 363| 364{6:Ok?} | 365{6:[O]k: }^ | 366]] ) 367-- And resizing the next event loop iteration also works. 368feed ( 'k' ) 369screen : try_resize ( screen . _width , screen . _height + 1 ) 370screen : expect ( [[ 371|*11 372{3: }| 373| 374{6:Ok?} | 375{6:[O]k: }^ | 376]] ) 377end ) 378end )