Mercurial > vim
comparison src/testdir/test_vim9_cmd.vim @ 22772:82a7aff951d2 v8.2.1934
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Commit: https://github.com/vim/vim/commit/e88c8e802cf5ee59a2a6649a5b46c9e80de823ad
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 1 17:03:37 2020 +0100
patch 8.2.1934: Vim9: command modifiers in :def function not tested
Problem: Vim9: command modifiers in :def function not tested.
Solution: Add tests. Fix using modifier before filter command.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Nov 2020 17:15:06 +0100 |
parents | f945413264d7 |
children | 3ec5f653f64d |
comparison
equal
deleted
inserted
replaced
22771:84263588f5be | 22772:82a7aff951d2 |
---|---|
1 " Test commands that are not compiled in a :def function | 1 " Test commands that are not compiled in a :def function |
2 | 2 |
3 source check.vim | 3 source check.vim |
4 source vim9.vim | 4 source vim9.vim |
5 source term_util.vim | |
5 source view_util.vim | 6 source view_util.vim |
6 | 7 |
7 def Test_edit_wildcards() | 8 def Test_edit_wildcards() |
8 var filename = 'Xtest' | 9 var filename = 'Xtest' |
9 edit `=filename` | 10 edit `=filename` |
310 var tags = [{'a': 1, 'b': 2}, {'x': 3, 'y': 4}] | 311 var tags = [{'a': 1, 'b': 2}, {'x': 3, 'y': 4}] |
311 filter(tags, { _, v -> has_key(v, 'x') ? 1 : 0 }) | 312 filter(tags, { _, v -> has_key(v, 'x') ? 1 : 0 }) |
312 assert_equal([#{x: 3, y: 4}], tags) | 313 assert_equal([#{x: 3, y: 4}], tags) |
313 enddef | 314 enddef |
314 | 315 |
315 def Test_filter_is_recognized() | 316 def Test_command_modifier_filter() |
316 var lines =<< trim END | 317 var lines =<< trim END |
317 final expected = "\nType Name Content\n c \"c piyo" | 318 final expected = "\nType Name Content\n c \"c piyo" |
318 @a = 'hoge' | 319 @a = 'hoge' |
319 @b = 'fuga' | 320 @b = 'fuga' |
320 @c = 'piyo' | 321 @c = 'piyo' |
321 | 322 |
322 assert_equal(execute('filter /piyo/ registers abc'), expected) | 323 assert_equal(execute('filter /piyo/ registers abc'), expected) |
323 END | 324 END |
324 CheckDefAndScriptSuccess(lines) | 325 CheckDefAndScriptSuccess(lines) |
326 enddef | |
327 | |
328 def Test_win_command_modifiers() | |
329 assert_equal(1, winnr('$')) | |
330 | |
331 set splitright | |
332 vsplit | |
333 assert_equal(2, winnr()) | |
334 close | |
335 aboveleft vsplit | |
336 assert_equal(1, winnr()) | |
337 close | |
338 set splitright& | |
339 | |
340 vsplit | |
341 assert_equal(1, winnr()) | |
342 close | |
343 belowright vsplit | |
344 assert_equal(2, winnr()) | |
345 close | |
346 rightbelow vsplit | |
347 assert_equal(2, winnr()) | |
348 close | |
349 | |
350 browse set | |
351 assert_equal('option-window', expand('%')) | |
352 close | |
353 | |
354 vsplit | |
355 botright split | |
356 assert_equal(3, winnr()) | |
357 assert_equal(&columns, winwidth(0)) | |
358 close | |
359 close | |
360 | |
361 vsplit | |
362 topleft split | |
363 assert_equal(1, winnr()) | |
364 assert_equal(&columns, winwidth(0)) | |
365 close | |
366 close | |
367 | |
368 gettabinfo()->len()->assert_equal(1) | |
369 tab split | |
370 gettabinfo()->len()->assert_equal(2) | |
371 tabclose | |
372 | |
373 vertical new | |
374 assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0)) | |
375 close | |
376 enddef | |
377 | |
378 func Test_command_modifier_confirm() | |
379 CheckNotGui | |
380 CheckRunVimInTerminal | |
381 | |
382 " Test for saving all the modified buffers | |
383 let lines =<< trim END | |
384 call setline(1, 'changed') | |
385 def Getout() | |
386 confirm write Xfile | |
387 enddef | |
388 END | |
389 call writefile(lines, 'Xconfirmscript') | |
390 call writefile(['empty'], 'Xfile') | |
391 let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8}) | |
392 call term_sendkeys(buf, ":call Getout()\n") | |
393 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000) | |
394 call term_sendkeys(buf, "y") | |
395 call StopVimInTerminal(buf) | |
396 | |
397 call assert_equal(['changed'], readfile('Xfile')) | |
398 call delete('Xfile') | |
399 call delete('Xconfirmscript') | |
400 endfunc | |
401 | |
402 def Test_command_modifiers_keep() | |
403 if has('unix') | |
404 def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool) | |
405 new | |
406 setline(1, ['one', 'two', 'three']) | |
407 normal 1Gma | |
408 normal 2Gmb | |
409 normal 3Gmc | |
410 if addRflag | |
411 set cpo+=R | |
412 else | |
413 set cpo-=R | |
414 endif | |
415 if keepMarks | |
416 keepmarks :%!cat | |
417 else | |
418 :%!cat | |
419 endif | |
420 if hasMarks | |
421 assert_equal(1, line("'a")) | |
422 assert_equal(2, line("'b")) | |
423 assert_equal(3, line("'c")) | |
424 else | |
425 assert_equal(0, line("'a")) | |
426 assert_equal(0, line("'b")) | |
427 assert_equal(0, line("'c")) | |
428 endif | |
429 quit! | |
430 enddef | |
431 DoTest(false, false, true) | |
432 DoTest(true, false, false) | |
433 DoTest(false, true, true) | |
434 DoTest(true, true, true) | |
435 set cpo&vim | |
436 endif | |
437 | |
438 # TODO | |
439 # lockmarks | |
440 # keepalt | |
441 # keeppatterns | |
442 # keepjumps | |
443 enddef | |
444 | |
445 def Test_command_modifier_other() | |
446 # TODO | |
447 # hide | |
448 # noautocmd | |
449 # noswapfile | |
450 # sandbox | |
451 # silent | |
452 # silent! | |
453 # unsilent | |
454 # verbose | |
325 enddef | 455 enddef |
326 | 456 |
327 def Test_eval_command() | 457 def Test_eval_command() |
328 var from = 3 | 458 var from = 3 |
329 var to = 5 | 459 var to = 5 |