aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/legacy/edit_spec.lua6
-rw-r--r--test/old/testdir/test_autoload.vim1
-rw-r--r--test/old/testdir/test_blob.vim20
-rw-r--r--test/old/testdir/test_edit.vim5
-rw-r--r--test/old/testdir/test_fold.vim57
-rw-r--r--test/old/testdir/test_functions.vim2
-rw-r--r--test/old/testdir/test_listdict.vim21
-rw-r--r--test/old/testdir/test_method.vim7
-rw-r--r--test/old/testdir/test_partial.vim14
-rw-r--r--test/old/testdir/test_spellrare.vim18
-rw-r--r--test/old/testdir/test_substitute.vim14
-rw-r--r--test/old/testdir/test_vimscript.vim8
12 files changed, 163 insertions, 10 deletions
diff --git a/test/functional/legacy/edit_spec.lua b/test/functional/legacy/edit_spec.lua
index f3d18a2541..2d98188f9b 100644
--- a/test/functional/legacy/edit_spec.lua
+++ b/test/functional/legacy/edit_spec.lua
@@ -44,6 +44,12 @@ describe('edit', function()
{1:~ }|*4
=^ |
]])
+ feed([['r'<CR><Esc>]])
+ expect('r')
+ -- Test for inserting null and empty list
+ feed('a<C-R>=v:_null_list<CR><Esc>')
+ feed('a<C-R>=[]<CR><Esc>')
+ expect('r')
end)
-- oldtest: Test_edit_ctrl_r_failed()
diff --git a/test/old/testdir/test_autoload.vim b/test/old/testdir/test_autoload.vim
index e89fe3943b..156387a2d2 100644
--- a/test/old/testdir/test_autoload.vim
+++ b/test/old/testdir/test_autoload.vim
@@ -21,5 +21,4 @@ func Test_source_autoload()
call assert_equal(1, g:loaded_sourced_vim)
endfunc
-
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_blob.vim b/test/old/testdir/test_blob.vim
index 3886be48bd..fbc080059e 100644
--- a/test/old/testdir/test_blob.vim
+++ b/test/old/testdir/test_blob.vim
@@ -75,6 +75,13 @@ func Test_blob_assign()
VAR l = [0z12]
VAR m = deepcopy(l)
LET m[0] = 0z34 #" E742 or E741 should not occur.
+
+ VAR blob1 = 0z10
+ LET blob1 += v:_null_blob
+ call assert_equal(0z10, blob1)
+ LET blob1 = v:_null_blob
+ LET blob1 += 0z20
+ call assert_equal(0z20, blob1)
END
call CheckLegacyAndVim9Success(lines)
@@ -332,6 +339,17 @@ func Test_blob_for_loop()
call assert_equal(5, i)
END
call CheckLegacyAndVim9Success(lines)
+
+ " Test for skipping the loop var assignment in a for loop
+ let lines =<< trim END
+ VAR blob = 0z998877
+ VAR c = 0
+ for _ in blob
+ LET c += 1
+ endfor
+ call assert_equal(3, c)
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_concatenate()
@@ -851,6 +869,7 @@ func Test_indexof()
call assert_equal(-1, indexof(b, v:_null_string))
" Nvim doesn't have null functions
" call assert_equal(-1, indexof(b, test_null_function()))
+ call assert_equal(-1, indexof(b, ""))
let b = 0z01020102
call assert_equal(1, indexof(b, "v:val == 0x02", #{startidx: 0}))
@@ -862,6 +881,7 @@ func Test_indexof()
" failure cases
call assert_fails('let i = indexof(b, "val == 0xde")', 'E121:')
call assert_fails('let i = indexof(b, {})', 'E1256:')
+ call assert_fails('let i = indexof(b, " ")', 'E15:')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim
index d43dcc40c1..037282bf1a 100644
--- a/test/old/testdir/test_edit.vim
+++ b/test/old/testdir/test_edit.vim
@@ -1973,6 +1973,11 @@ func Test_edit_insert_reg()
let @r = 'sample'
call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt")
call assert_equal('"', g:Line)
+
+ " Test for inserting an null and an empty list
+ call feedkeys("a\<C-R>=test_null_list()\<CR>", "xt")
+ call feedkeys("a\<C-R>=[]\<CR>", "xt")
+ call assert_equal(['r'], getbufline('', 1, '$'))
call test_override('ALL', 0)
close!
endfunc
diff --git a/test/old/testdir/test_fold.vim b/test/old/testdir/test_fold.vim
index a9842ae437..36f72f5e01 100644
--- a/test/old/testdir/test_fold.vim
+++ b/test/old/testdir/test_fold.vim
@@ -1469,6 +1469,63 @@ func Test_foldtext_scriptlocal_func()
delfunc s:FoldText
endfunc
+" Test for setting 'foldtext' from the modeline and executing the expression
+" in a sandbox
+func Test_foldtext_in_modeline()
+ func ModelineFoldText()
+ call feedkeys('aFoo', 'xt')
+ return "folded text"
+ endfunc
+ let lines =<< trim END
+ func T()
+ let i = 1
+ endfunc
+ " vim: foldenable foldtext=ModelineFoldText()
+ END
+ call writefile(lines, 'Xmodelinefoldtext', 'D')
+
+ set modeline modelineexpr
+ split Xmodelinefoldtext
+
+ call cursor(1, 1)
+ normal! zf3j
+ call assert_equal('folded text', foldtextresult(1))
+ call assert_equal(lines, getbufline('', 1, '$'))
+
+ bw!
+ set modeline& modelineexpr&
+ delfunc ModelineFoldText
+endfunc
+
+" Test for setting 'foldexpr' from the modeline and executing the expression
+" in a sandbox
+func Test_foldexpr_in_modeline()
+ func ModelineFoldExpr()
+ call feedkeys('aFoo', 'xt')
+ return strlen(matchstr(getline(v:lnum),'^\s*'))
+ endfunc
+ let lines =<< trim END
+ aaa
+ bbb
+ ccc
+ ccc
+ bbb
+ aaa
+ " vim: foldenable foldmethod=expr foldexpr=ModelineFoldExpr()
+ END
+ call writefile(lines, 'Xmodelinefoldexpr', 'D')
+
+ set modeline modelineexpr
+ split Xmodelinefoldexpr
+
+ call assert_equal(2, foldlevel(3))
+ call assert_equal(lines, getbufline('', 1, '$'))
+
+ bw!
+ set modeline& modelineexpr&
+ delfunc ModelineFoldExpr
+endfunc
+
" Make sure a fold containing a nested fold is split correctly when using
" foldmethod=indent
func Test_fold_split()
diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim
index 3faa720850..01e9ae3bf2 100644
--- a/test/old/testdir/test_functions.vim
+++ b/test/old/testdir/test_functions.vim
@@ -3731,6 +3731,8 @@ func Test_slice()
call assert_equal('', 'ὰ̳β̳́γ̳̂δ̳̃ε̳̄ζ̳̅'->slice(1, -6))
END
call CheckLegacyAndVim9Success(lines)
+
+ call assert_equal(0, slice(v:true, 1))
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim
index 5e4a3fd1f8..678734dafb 100644
--- a/test/old/testdir/test_listdict.vim
+++ b/test/old/testdir/test_listdict.vim
@@ -57,6 +57,9 @@ func Test_list_slice()
assert_equal([1, 2], l[-3 : -1])
END
call CheckDefAndScriptSuccess(lines)
+
+ call assert_fails('let l[[]] = 1', 'E730: Using a List as a String')
+ call assert_fails('let l[1 : []] = [1]', 'E730: Using a List as a String')
endfunc
" List identity
@@ -175,6 +178,19 @@ func Test_list_assign()
END
call CheckScriptFailure(['vim9script'] + lines, 'E688:')
call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
+
+ let lines =<< trim END
+ VAR l = [2]
+ LET l += v:_null_list
+ call assert_equal([2], l)
+ LET l = v:_null_list
+ LET l += [1]
+ call assert_equal([1], l)
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let d = {'abc': [1, 2, 3]}
+ call assert_fails('let d.abc[0:0z10] = [10, 20]', 'E976: Using a Blob as a String')
endfunc
" test for range assign
@@ -440,6 +456,9 @@ func Test_dict_assign()
n.key = 3
END
call CheckDefFailure(lines, 'E1141:')
+
+ let d = {'abc': {}}
+ call assert_fails("let d.abc[0z10] = 10", 'E976: Using a Blob as a String')
endfunc
" Function in script-local List or Dict
@@ -1449,6 +1468,8 @@ func Test_indexof()
call assert_equal(-1, indexof(l, v:_null_string))
" Nvim doesn't have null functions
" call assert_equal(-1, indexof(l, test_null_function()))
+ call assert_equal(-1, indexof(l, ""))
+ call assert_fails('let i = indexof(l, " ")', 'E15:')
" failure cases
call assert_fails('let i = indexof(l, "v:val == ''cyan''")', 'E735:')
diff --git a/test/old/testdir/test_method.vim b/test/old/testdir/test_method.vim
index 1b57bba282..ca1ca7d573 100644
--- a/test/old/testdir/test_method.vim
+++ b/test/old/testdir/test_method.vim
@@ -134,6 +134,13 @@ func Test_method_syntax()
call assert_fails('eval [1, 2, 3]-> sort()', 'E15:')
call assert_fails('eval [1, 2, 3]->sort ()', 'E274:')
call assert_fails('eval [1, 2, 3]-> sort ()', 'E15:')
+
+ " Test for using a method name containing a curly brace name
+ let s = 'len'
+ call assert_equal(4, "xxxx"->str{s}())
+
+ " Test for using a method in an interpolated string
+ call assert_equal('4', $'{"xxxx"->strlen()}')
endfunc
func Test_method_lambda()
diff --git a/test/old/testdir/test_partial.vim b/test/old/testdir/test_partial.vim
index d049cc9e4b..b5933cdd6d 100644
--- a/test/old/testdir/test_partial.vim
+++ b/test/old/testdir/test_partial.vim
@@ -403,4 +403,18 @@ func Test_compare_partials()
call assert_false(F1 is N1)
endfunc
+func Test_partial_method()
+ func Foo(x, y, z)
+ return x + y + z
+ endfunc
+ let d = {"Fn": function('Foo', [10, 20])}
+ call assert_fails('echo 30->d.Fn()', 'E1265: Cannot use a partial here')
+ delfunc Foo
+endfunc
+
+func Test_non_callable_type_as_method()
+ let d = {"Fn": 10}
+ call assert_fails('echo 30->d.Fn()', 'E1085: Not a callable type: d.Fn')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_spellrare.vim b/test/old/testdir/test_spellrare.vim
index bbb13c27c2..ceb35cbd17 100644
--- a/test/old/testdir/test_spellrare.vim
+++ b/test/old/testdir/test_spellrare.vim
@@ -11,15 +11,15 @@ func Test_spellrareword()
" Create a small word list to test that spellbadword('...')
" can return ['...', 'rare'].
let lines =<< trim END
- foo
- foobar/?
- foobara/?
-END
- call writefile(lines, 'Xwords', 'D')
-
- mkspell! Xwords.spl Xwords
- set spelllang=Xwords.spl
- call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
+ foo
+ foobar/?
+ foobara/?
+ END
+ call writefile(lines, 'Xwords', 'D')
+
+ mkspell! Xwords.spl Xwords
+ set spelllang=Xwords.spl
+ call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
new
call setline(1, ['foo', '', 'foo bar foo bar foobara foo foo foo foobar', '', 'End'])
diff --git a/test/old/testdir/test_substitute.vim b/test/old/testdir/test_substitute.vim
index f69a3c525b..f0a25b2804 100644
--- a/test/old/testdir/test_substitute.vim
+++ b/test/old/testdir/test_substitute.vim
@@ -1507,4 +1507,18 @@ func Test_substitute_expr_recursive()
exe bufnr .. "bw!"
endfunc
+" Test for changing 'cpo' in a substitute expression
+func Test_substitute_expr_cpo()
+ func XSubExpr()
+ set cpo=
+ return 'x'
+ endfunc
+
+ let save_cpo = &cpo
+ call assert_equal('xxx', substitute('abc', '.', '\=XSubExpr()', 'g'))
+ call assert_equal(save_cpo, &cpo)
+
+ delfunc XSubExpr
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_vimscript.vim b/test/old/testdir/test_vimscript.vim
index 28868a07d6..7f29c7f651 100644
--- a/test/old/testdir/test_vimscript.vim
+++ b/test/old/testdir/test_vimscript.vim
@@ -7449,6 +7449,14 @@ func Test_for_over_string()
let res ..= c .. '-'
endfor
call assert_equal('', res)
+
+ " Test for using "_" as the loop variable
+ let i = 0
+ let s = 'abc'
+ for _ in s
+ call assert_equal(s[i], _)
+ let i += 1
+ endfor
endfunc
" Test for deeply nested :source command {{{1