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