diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2022-10-26 21:34:18 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-26 21:34:18 +0800 |
| commit | c00e711d5a860fb019f594d164b4327d942313f8 (patch) | |
| tree | 6b88d5ab645201a103cad3a67a98eadb07e6e5b4 /src/nvim/testdir/test_vimscript.vim | |
| parent | d60fa43466eaf59999e39860ce6d0ce2fa2cfb36 (diff) | |
| parent | 46a54dd6a03f51ba08142abe0aa5710705917987 (diff) | |
| download | rneovim-c00e711d5a860fb019f594d164b4327d942313f8.tar.gz rneovim-c00e711d5a860fb019f594d164b4327d942313f8.tar.bz2 rneovim-c00e711d5a860fb019f594d164b4327d942313f8.zip | |
Merge pull request #20814 from zeertzjq/vim-8.2.0610
vim-patch:8.2.{0610,0619,1852}
Diffstat (limited to 'src/nvim/testdir/test_vimscript.vim')
| -rw-r--r-- | src/nvim/testdir/test_vimscript.vim | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 7a75d0e88a..a9fd7a4bef 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1658,6 +1658,20 @@ func Test_compound_assignment_operators() call assert_fails('let x .= "f"', 'E734') let x = !3.14 call assert_equal(0.0, x) + + " integer and float operations + let x = 1 + let x *= 2.1 + call assert_equal(2.1, x) + let x = 1 + let x /= 0.25 + call assert_equal(4.0, x) + let x = 1 + call assert_fails('let x %= 0.25', 'E734:') + let x = 1 + call assert_fails('let x .= 0.25', 'E734:') + let x = 1.0 + call assert_fails('let x += [1.1]', 'E734:') endif " Test for environment variable @@ -1839,6 +1853,9 @@ func Test_missing_end() " Missing 'in' in a :for statement call assert_fails('for i range(1) | endfor', 'E690:') + + " Incorrect number of variables in for + call assert_fails('for [i,] in range(3) | endfor', 'E475:') endfunc " Test for deep nesting of if/for/while/try statements {{{1 @@ -1958,6 +1975,86 @@ func Test_float_conversion_errors() endif endfunc +func Test_invalid_function_names() + " function name not starting with capital + let caught_e128 = 0 + try + func! g:test() + echo "test" + endfunc + catch /E128:/ + let caught_e128 = 1 + endtry + call assert_equal(1, caught_e128) + + " function name includes a colon + let caught_e884 = 0 + try + func! b:test() + echo "test" + endfunc + catch /E884:/ + let caught_e884 = 1 + endtry + call assert_equal(1, caught_e884) + + " function name folowed by # + let caught_e128 = 0 + try + func! test2() "# + echo "test2" + endfunc + catch /E128:/ + let caught_e128 = 1 + endtry + call assert_equal(1, caught_e128) + + " function name starting with/without "g:", buffer-local funcref. + function! g:Foo(n) + return 'called Foo(' . a:n . ')' + endfunction + let b:my_func = function('Foo') + call assert_equal('called Foo(1)', b:my_func(1)) + call assert_equal('called Foo(2)', g:Foo(2)) + call assert_equal('called Foo(3)', Foo(3)) + delfunc g:Foo + + " script-local function used in Funcref must exist. + let lines =<< trim END + func s:Testje() + return "foo" + endfunc + let Bar = function('s:Testje') + call assert_equal(0, exists('s:Testje')) + call assert_equal(1, exists('*s:Testje')) + call assert_equal(1, exists('Bar')) + call assert_equal(1, exists('*Bar')) + END + call writefile(lines, 'Xscript') + source Xscript + call delete('Xscript') +endfunc + +" substring and variable name +func Test_substring_var() + let str = 'abcdef' + let n = 3 + call assert_equal('def', str[n:]) + call assert_equal('abcd', str[:n]) + call assert_equal('d', str[n:n]) + unlet n + let nn = 3 + call assert_equal('def', str[nn:]) + call assert_equal('abcd', str[:nn]) + call assert_equal('d', str[nn:nn]) + unlet nn + let b:nn = 4 + call assert_equal('ef', str[b:nn:]) + call assert_equal('abcde', str[:b:nn]) + call assert_equal('e', str[b:nn:b:nn]) + unlet b:nn +endfunc + func Test_for_over_string() let res = '' for c in 'aéc̀d' |