cmdline2_spec.lua (11170B)
1 -- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI. 2 3 local t = require('test.testutil') 4 local n = require('test.functional.testnvim')() 5 local Screen = require('test.functional.ui.screen') 6 7 local clear, exec, exec_lua, feed = n.clear, n.exec, n.exec_lua, n.feed 8 9 describe('cmdline2', function() 10 local screen 11 before_each(function() 12 clear() 13 screen = Screen.new() 14 screen:add_extra_attr_ids({ 15 [100] = { foreground = Screen.colors.Magenta1, bold = true }, 16 [101] = { background = Screen.colors.Yellow, foreground = Screen.colors.Grey0 }, 17 }) 18 exec_lua(function() 19 require('vim._core.ui2').enable({}) 20 end) 21 end) 22 23 it("no crash for invalid grid after 'cmdheight' OptionSet", function() 24 exec('tabnew | tabprev') 25 feed(':set ch=0') 26 screen:expect([[ 27 {5: [No Name] }{24: [No Name] }{2: }{24:X}| 28 | 29 {1:~ }|*11 30 {16::}{15:set} {16:ch}{15:=}0^ | 31 ]]) 32 feed('<CR>') 33 exec('tabnext') 34 screen:expect([[ 35 {24: [No Name] }{5: [No Name] }{2: }{24:X}| 36 ^ | 37 {1:~ }|*11 38 {16::}{15:set} {16:ch}{15:=}0 | 39 ]]) 40 exec('tabnext') 41 screen:expect([[ 42 {5: [No Name] }{24: [No Name] }{2: }{24:X}| 43 ^ | 44 {1:~ }|*12 45 ]]) 46 n.assert_alive() 47 end) 48 49 it("redraw does not clear 'incsearch' highlight with conceal", function() 50 exec('call setline(1, ["foo", "foobar"]) | set conceallevel=1 concealcursor=c') 51 feed('/foo') 52 screen:expect([[ 53 {10:foo} | 54 {2:foo}bar | 55 {1:~ }|*11 56 /foo^ | 57 ]]) 58 end) 59 60 it('block mode', function() 61 feed(':if 1<CR>') 62 screen:expect([[ 63 | 64 {1:~ }|*11 65 {16::}{15:if} {26:1} | 66 {16::} ^ | 67 ]]) 68 feed('echo "foo"') 69 screen:expect([[ 70 | 71 {1:~ }|*11 72 {16::}{15:if} {26:1} | 73 {16::} {15:echo} {26:"foo"}^ | 74 ]]) 75 feed('<CR>') 76 screen:expect([[ 77 | 78 {1:~ }|*9 79 {16::}{15:if} {26:1} | 80 {16::} {15:echo} {26:"foo"} | 81 {15:foo} | 82 {16::} ^ | 83 ]]) 84 feed([[echo input("foo\nbar:")<CR>]]) 85 screen:expect([[ 86 | 87 {1:~ }|*7 88 :if 1 | 89 : echo "foo" | 90 foo | 91 : echo input("foo\nbar:") | 92 foo | 93 bar:^ | 94 ]]) 95 feed('baz') 96 screen:expect([[ 97 | 98 {1:~ }|*7 99 :if 1 | 100 : echo "foo" | 101 foo | 102 : echo input("foo\nbar:") | 103 foo | 104 bar:baz^ | 105 ]]) 106 feed('<CR>') 107 screen:expect([[ 108 | 109 {1:~ }|*5 110 {16::}{15:if} {26:1} | 111 {16::} {15:echo} {26:"foo"} | 112 {15:foo} | 113 {16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 114 {15:foo} | 115 {15:bar}:baz | 116 {15:baz} | 117 {16::} ^ | 118 ]]) 119 feed('endif') 120 screen:expect([[ 121 | 122 {1:~ }|*5 123 {16::}{15:if} {26:1} | 124 {16::} {15:echo} {26:"foo"} | 125 {15:foo} | 126 {16::} {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)} | 127 {15:foo} | 128 {15:bar}:baz | 129 {15:baz} | 130 {16::} {15:endif}^ | 131 ]]) 132 feed('<CR>') 133 screen:expect([[ 134 ^ | 135 {1:~ }|*12 136 | 137 ]]) 138 end) 139 140 it('handles empty prompt', function() 141 feed(":call input('')<CR>") 142 screen:expect([[ 143 | 144 {1:~ }|*12 145 ^ | 146 ]]) 147 end) 148 149 it('highlights after deleting buffer', function() 150 feed(':sil %bw!<CR>:call foo()') 151 screen:expect([[ 152 | 153 {1:~ }|*12 154 {16::}{15:call} {25:foo}{16:()}^ | 155 ]]) 156 end) 157 158 it('can change cmdline buffer during textlock', function() 159 exec([[ 160 func Foo(a, b) 161 redrawstatus! 162 endfunc 163 set wildoptions=pum findfunc=Foo wildmode=noselect:lastused,full 164 au CmdlineChanged * call wildtrigger() 165 ]]) 166 feed(':find ') 167 screen:expect([[ 168 | 169 {1:~ }|*12 170 {16::}{15:find} ^ | 171 ]]) 172 t.eq(n.eval('v:errmsg'), "E1514: 'findfunc' did not return a List type") 173 end) 174 175 it('substitution match does not clear cmdline', function() 176 exec('call setline(1, "foo")') 177 feed(':s/f') 178 screen:expect([[ 179 {10:f}oo | 180 {1:~ }|*12 181 {16::}{15:s}{16:/f}^ | 182 ]]) 183 end) 184 185 it('dialog position is adjusted for toggled non-pum wildmenu', function() 186 exec([[ 187 set wildmode=list:full,full wildoptions-=pum 188 func Foo() 189 endf 190 func Fooo() 191 endf 192 ]]) 193 feed(':call Fo<C-Z>') 194 screen:expect([[ 195 | 196 {1:~ }|*9 197 {3: }| 198 Foo() Fooo() | 199 | 200 {16::}{15:call} Fo^ | 201 ]]) 202 feed('<C-Z>') 203 screen:expect([[ 204 | 205 {1:~ }|*8 206 {3: }| 207 Foo() Fooo() | 208 | 209 {101:Foo()}{3: Fooo() }| 210 {16::}{15:call} {25:Foo}{16:()}^ | 211 ]]) 212 feed('<BS><BS>') 213 exec('set wildoptions+=pum laststatus=2') 214 screen:expect([[ 215 | 216 {1:~ }|*9 217 {3: }| 218 Foo() Fooo() | 219 | 220 {16::}{15:call} Foo^ | 221 ]]) 222 feed('<C-Z><C-Z>') 223 screen:expect([[ 224 | 225 {1:~ }|*9 226 {3: }| 227 Foo(){12: Foo() } | 228 {4: Fooo() } | 229 {16::}{15:call} {25:Foo}{16:()}^ | 230 ]]) 231 end) 232 end) 233 234 describe('cmdline2', function() 235 it('resizing during startup shows confirm prompt #36439', function() 236 clear({ 237 args = { 238 '--clean', 239 '+lua require("vim._core.ui2").enable({})', 240 "+call feedkeys(':')", 241 }, 242 }) 243 local screen = Screen.new() 244 feed('call confirm("Ok?")<CR>') 245 screen:try_resize(screen._width + 1, screen._height) 246 screen:expect([[ 247 |*10 248 {3: }| 249 | 250 {6:Ok?} | 251 {6:[O]k: }^ | 252 ]]) 253 -- And resizing the next event loop iteration also works. 254 feed('k') 255 screen:try_resize(screen._width, screen._height + 1) 256 screen:expect([[ 257 |*11 258 {3: }| 259 | 260 {6:Ok?} | 261 {6:[O]k: }^ | 262 ]]) 263 end) 264 end)