Mercurial > vim
comparison src/testdir/test_expr.vim @ 19724:b3e93a05c3ca v8.2.0418
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Commit: https://github.com/vim/vim/commit/8b633135106dda8605463b780573c45b00c22afe
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 20 18:20:51 2020 +0100
patch 8.2.0418: code in eval.c not sufficiently covered by tests
Problem: Code in eval.c not sufficiently covered by tests.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5815)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 20 Mar 2020 18:30:05 +0100 |
parents | fdfe44ac6a1a |
children | 546bdeef35f1 |
comparison
equal
deleted
inserted
replaced
19723:16aa117306ec | 19724:b3e93a05c3ca |
---|---|
71 call assert_equal('', strcharpart('axb', 1, -1)) | 71 call assert_equal('', strcharpart('axb', 1, -1)) |
72 call assert_equal('', strcharpart('axb', -1, 1)) | 72 call assert_equal('', strcharpart('axb', -1, 1)) |
73 call assert_equal('', strcharpart('axb', -2, 2)) | 73 call assert_equal('', strcharpart('axb', -2, 2)) |
74 | 74 |
75 call assert_equal('a', strcharpart('axb', -1, 2)) | 75 call assert_equal('a', strcharpart('axb', -1, 2)) |
76 | |
77 call assert_equal('edit', "editor"[-10:3]) | |
76 endfunc | 78 endfunc |
77 | 79 |
78 func Test_getreg_empty_list() | 80 func Test_getreg_empty_list() |
79 call assert_equal('', getreg('x')) | 81 call assert_equal('', getreg('x')) |
80 call assert_equal([], getreg('x', 1, 1)) | 82 call assert_equal([], getreg('x', 1, 1)) |
474 call assert_equal(v:t_string, s:fref('x')) | 476 call assert_equal(v:t_string, s:fref('x')) |
475 call assert_fails("call function('s:f')", 'E700:') | 477 call assert_fails("call function('s:f')", 'E700:') |
476 | 478 |
477 call assert_fails("call function('foo()')", 'E475:') | 479 call assert_fails("call function('foo()')", 'E475:') |
478 call assert_fails("call function('foo()')", 'foo()') | 480 call assert_fails("call function('foo()')", 'foo()') |
481 call assert_fails("function('')", 'E129:') | |
479 endfunc | 482 endfunc |
480 | 483 |
481 func Test_funcref() | 484 func Test_funcref() |
482 func! One() | 485 func! One() |
483 return 1 | 486 return 1 |
531 let s:val ..= a:x | 534 let s:val ..= a:x |
532 endfunc | 535 endfunc |
533 if 0 | eval SetVal('a') | endif | call SetVal('b') | 536 if 0 | eval SetVal('a') | endif | call SetVal('b') |
534 call assert_equal('b', s:val) | 537 call assert_equal('b', s:val) |
535 endfunc | 538 endfunc |
539 | |
540 " Test for command-line completion of expressions | |
541 func Test_expr_completion() | |
542 if !has('cmdline_compl') | |
543 return | |
544 endif | |
545 for cmd in [ | |
546 \ 'let a = ', | |
547 \ 'const a = ', | |
548 \ 'if', | |
549 \ 'elseif', | |
550 \ 'while', | |
551 \ 'for', | |
552 \ 'echo', | |
553 \ 'echon', | |
554 \ 'execute', | |
555 \ 'echomsg', | |
556 \ 'echoerr', | |
557 \ 'call', | |
558 \ 'return', | |
559 \ 'cexpr', | |
560 \ 'caddexpr', | |
561 \ 'cgetexpr', | |
562 \ 'lexpr', | |
563 \ 'laddexpr', | |
564 \ 'lgetexpr'] | |
565 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') | |
566 call assert_equal('"' . cmd . ' getline(', getreg(':')) | |
567 endfor | |
568 | |
569 " completion for the expression register | |
570 call feedkeys(":\"\<C-R>=float2\t\"\<C-B>\"\<CR>", 'xt') | |
571 call assert_equal('"float2nr("', @=) | |
572 | |
573 " completion for window local variables | |
574 let w:wvar1 = 10 | |
575 let w:wvar2 = 10 | |
576 call feedkeys(":echo w:wvar\<C-A>\<C-B>\"\<CR>", 'xt') | |
577 call assert_equal('"echo w:wvar1 w:wvar2', @:) | |
578 unlet w:wvar1 w:wvar2 | |
579 | |
580 " completion for tab local variables | |
581 let t:tvar1 = 10 | |
582 let t:tvar2 = 10 | |
583 call feedkeys(":echo t:tvar\<C-A>\<C-B>\"\<CR>", 'xt') | |
584 call assert_equal('"echo t:tvar1 t:tvar2', @:) | |
585 unlet t:tvar1 t:tvar2 | |
586 | |
587 " completion for variables | |
588 let g:tvar1 = 1 | |
589 let g:tvar2 = 2 | |
590 call feedkeys(":let g:tv\<C-A>\<C-B>\"\<CR>", 'xt') | |
591 call assert_equal('"let g:tvar1 g:tvar2', @:) | |
592 " completion for variables after a || | |
593 call feedkeys(":echo 1 || g:tv\<C-A>\<C-B>\"\<CR>", 'xt') | |
594 call assert_equal('"echo 1 || g:tvar1 g:tvar2', @:) | |
595 | |
596 " completion for options | |
597 call feedkeys(":echo &compat\<C-A>\<C-B>\"\<CR>", 'xt') | |
598 call assert_equal('"echo &compatible', @:) | |
599 call feedkeys(":echo 1 && &compat\<C-A>\<C-B>\"\<CR>", 'xt') | |
600 call assert_equal('"echo 1 && &compatible', @:) | |
601 call feedkeys(":echo &g:equala\<C-A>\<C-B>\"\<CR>", 'xt') | |
602 call assert_equal('"echo &g:equalalways', @:) | |
603 | |
604 " completion for string | |
605 call feedkeys(":echo \"Hello\\ World\"\<C-A>\<C-B>\"\<CR>", 'xt') | |
606 call assert_equal("\"echo \"Hello\\ World\"\<C-A>", @:) | |
607 call feedkeys(":echo 'Hello World'\<C-A>\<C-B>\"\<CR>", 'xt') | |
608 call assert_equal("\"echo 'Hello World'\<C-A>", @:) | |
609 | |
610 " completion for command after a | | |
611 call feedkeys(":echo 'Hello' | cwin\<C-A>\<C-B>\"\<CR>", 'xt') | |
612 call assert_equal("\"echo 'Hello' | cwindow", @:) | |
613 | |
614 " completion for environment variable | |
615 let $X_VIM_TEST_COMPLETE_ENV = 'foo' | |
616 call feedkeys(":let $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') | |
617 call assert_match('"let $X_VIM_TEST_COMPLETE_ENV', @:) | |
618 unlet $X_VIM_TEST_COMPLETE_ENV | |
619 endfunc | |
620 | |
621 " Test for errors in expression evaluation | |
622 func Test_expr_eval_error() | |
623 call assert_fails("let i = 'abc' . []", 'E730:') | |
624 call assert_fails("let l = [] + 10", 'E745:') | |
625 call assert_fails("let v = 10 + []", 'E745:') | |
626 call assert_fails("let v = 10 / []", 'E745:') | |
627 call assert_fails("let v = -{}", 'E728:') | |
628 endfunc | |
629 | |
630 " vim: shiftwidth=2 sts=2 expandtab |