diff options
Diffstat (limited to 'test/old')
-rw-r--r-- | test/old/testdir/test_debugger.vim | 33 | ||||
-rw-r--r-- | test/old/testdir/test_eval_stuff.vim | 5 | ||||
-rw-r--r-- | test/old/testdir/test_expr.vim | 56 | ||||
-rw-r--r-- | test/old/testdir/test_let.vim | 120 | ||||
-rw-r--r-- | test/old/testdir/test_scriptnames.vim | 4 |
5 files changed, 214 insertions, 4 deletions
diff --git a/test/old/testdir/test_debugger.vim b/test/old/testdir/test_debugger.vim index f5177c8fb2..18616e8717 100644 --- a/test/old/testdir/test_debugger.vim +++ b/test/old/testdir/test_debugger.vim @@ -348,6 +348,39 @@ func Test_Debugger_breakadd() call assert_fails('breakadd file Xtest.vim /\)/', 'E55:') endfunc +" Test for expression breakpoint set using ":breakadd expr <expr>" +func Test_Debugger_breakadd_expr() + CheckRunVimInTerminal + let lines =<< trim END + let g:Xtest_var += 1 + END + call writefile(lines, 'Xtest.vim') + + " Start Vim in a terminal + let buf = RunVimInTerminal('Xtest.vim', {}) + call RunDbgCmd(buf, ':let g:Xtest_var = 10') + call RunDbgCmd(buf, ':breakadd expr g:Xtest_var') + call RunDbgCmd(buf, ':source %') + let expected =<< eval trim END + Oldval = "10" + Newval = "11" + {fnamemodify('Xtest.vim', ':p')} + line 1: let g:Xtest_var += 1 + END + call RunDbgCmd(buf, ':source %', expected) + call RunDbgCmd(buf, 'cont') + let expected =<< eval trim END + Oldval = "11" + Newval = "12" + {fnamemodify('Xtest.vim', ':p')} + line 1: let g:Xtest_var += 1 + END + call RunDbgCmd(buf, ':source %', expected) + + call StopVimInTerminal(buf) + call delete('Xtest.vim') +endfunc + func Test_Backtrace_Through_Source() CheckRunVimInTerminal CheckCWD diff --git a/test/old/testdir/test_eval_stuff.vim b/test/old/testdir/test_eval_stuff.vim index 90e3942c4d..7acc91c17b 100644 --- a/test/old/testdir/test_eval_stuff.vim +++ b/test/old/testdir/test_eval_stuff.vim @@ -407,4 +407,9 @@ func Test_modified_char_no_escape_special() nunmap <M-…> endfunc +func Test_eval_string_in_special_key() + " this was using the '{' inside <> as the start of an interpolated string + silent! echo 0{1-$"\<S--{>n|nö% +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim index c8b7fde100..dee7266bb5 100644 --- a/test/old/testdir/test_expr.vim +++ b/test/old/testdir/test_expr.vim @@ -848,4 +848,60 @@ func Test_float_compare() call CheckLegacyAndVim9Success(lines) endfunc +func Test_string_interp() + let lines =<< trim END + call assert_equal('', $"") + call assert_equal('foobar', $"foobar") + #" Escaping rules. + call assert_equal('"foo"{bar}', $"\"foo\"{{bar}}") + call assert_equal('"foo"{bar}', $'"foo"{{bar}}') + call assert_equal('foobar', $"{"foo"}" .. $'{'bar'}') + #" Whitespace before/after the expression. + call assert_equal('3', $"{ 1 + 2 }") + #" String conversion. + call assert_equal('hello from ' .. v:version, $"hello from {v:version}") + call assert_equal('hello from ' .. v:version, $'hello from {v:version}') + #" Paper over a small difference between VimScript behaviour. + call assert_equal(string(v:true), $"{v:true}") + call assert_equal('(1+1=2)', $"(1+1={1 + 1})") + #" Hex-escaped opening brace: char2nr('{') == 0x7b + call assert_equal('esc123ape', $"esc{123}ape") + call assert_equal('me{}me', $"me{"\x7b"}\x7dme") + VAR var1 = "sun" + VAR var2 = "shine" + call assert_equal('sunshine', $"{var1}{var2}") + call assert_equal('sunsunsun', $"{var1->repeat(3)}") + #" Multibyte strings. + call assert_equal('say ハロー・ワールド', $"say {'ハロー・ワールド'}") + #" Nested. + call assert_equal('foobarbaz', $"foo{$"{'bar'}"}baz") + #" Do not evaluate blocks when the expr is skipped. + VAR tmp = 0 + if v:false + echo "${ LET tmp += 1 }" + endif + call assert_equal(0, tmp) + + #" Stray closing brace. + call assert_fails('echo $"moo}"', 'E1278:') + #" Undefined variable in expansion. + call assert_fails('echo $"{moo}"', 'E121:') + #" Empty blocks are rejected. + call assert_fails('echo $"{}"', 'E15:') + call assert_fails('echo $"{ }"', 'E15:') + END + call CheckLegacyAndVim9Success(lines) + + let lines =<< trim END + call assert_equal('5', $"{({x -> x + 1})(4)}") + END + call CheckLegacySuccess(lines) + + let lines =<< trim END + call assert_equal('5', $"{((x) => x + 1)(4)}") + call assert_fails('echo $"{ # foo }"', 'E1279:') + END + call CheckDefAndScriptSuccess(lines) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_let.vim b/test/old/testdir/test_let.vim index 6fbf305624..0d84164274 100644 --- a/test/old/testdir/test_let.vim +++ b/test/old/testdir/test_let.vim @@ -1,5 +1,7 @@ " Tests for the :let command. +source vim9.vim + func Test_let() " Test to not autoload when assigning. It causes internal error. set runtimepath+=./sautest @@ -385,7 +387,18 @@ END call assert_equal(['Text', 'with', 'indent'], text) endfunc -" Test for the setting a variable using the heredoc syntax +func Test_let_interpolated() + call assert_equal('{text}', $'{{text}}') + call assert_equal('{{text}}', $'{{{{text}}}}') + let text = 'text' + call assert_equal('text{{', $'{text .. "{{"}') + call assert_equal('text{{', $"{text .. '{{'}") + call assert_equal('text{{', $'{text .. '{{'}') + call assert_equal('text{{', $"{text .. "{{"}") +endfunc + +" Test for the setting a variable using the heredoc syntax. +" Keep near the end, this messes up highlighting. func Test_let_heredoc() let var1 =<< END Some sample text @@ -493,4 +506,109 @@ END call assert_equal([' x', ' \y', ' z'], [a, b, c]) endfunc +" Test for evaluating Vim expressions in a heredoc using {expr} +" Keep near the end, this messes up highlighting. +func Test_let_heredoc_eval() + let str = '' + let code =<< trim eval END + let a = {5 + 10} + let b = {min([10, 6])} + {max([4, 6])} + {str} + let c = "abc{str}d" + END + call assert_equal(['let a = 15', 'let b = 6 + 6', '', 'let c = "abcd"'], code) + + let $TESTVAR = "Hello" + let code =<< eval trim END + let s = "{$TESTVAR}" + END + call assert_equal(['let s = "Hello"'], code) + + let code =<< eval END + let s = "{$TESTVAR}" +END + call assert_equal([' let s = "Hello"'], code) + + let a = 10 + let data =<< eval END +{a} +END + call assert_equal(['10'], data) + + let x = 'X' + let code =<< eval trim END + let a = {{abc}} + let b = {x} + let c = {{ + END + call assert_equal(['let a = {abc}', 'let b = X', 'let c = {'], code) + + let code = 'xxx' + let code =<< eval trim END + let n = {5 + + 6} + END + call assert_equal('xxx', code) + + let code =<< eval trim END + let n = {min([1, 2]} + {max([3, 4])} + END + call assert_equal('xxx', code) + + let lines =<< trim LINES + let text =<< eval trim END + let b = { + END + LINES + call CheckScriptFailure(lines, 'E1279:') + + let lines =<< trim LINES + let text =<< eval trim END + let b = {abc + END + LINES + call CheckScriptFailure(lines, 'E1279:') + + let lines =<< trim LINES + let text =<< eval trim END + let b = {} + END + LINES + call CheckScriptFailure(lines, 'E15:') + + " skipped heredoc + if 0 + let msg =<< trim eval END + n is: {n} + END + endif + + " Test for sourcing a script containing a heredoc with invalid expression. + " Variable assignment should fail, if expression evaluation fails + new + let g:Xvar = 'test' + let g:b = 10 + let lines =<< trim END + let Xvar =<< eval CODE + let a = 1 + let b = {5+} + let c = 2 + CODE + let g:Count += 1 + END + call setline(1, lines) + let g:Count = 0 + call assert_fails('source', 'E15:') + call assert_equal(1, g:Count) + call setline(3, 'let b = {abc}') + call assert_fails('source', 'E121:') + call assert_equal(2, g:Count) + call setline(3, 'let b = {abc} + {min([9, 4])} + 2') + call assert_fails('source', 'E121:') + call assert_equal(3, g:Count) + call assert_equal('test', g:Xvar) + call assert_equal(10, g:b) + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim index d804684722..06ae305ab7 100644 --- a/test/old/testdir/test_scriptnames.vim +++ b/test/old/testdir/test_scriptnames.vim @@ -35,9 +35,7 @@ func Test_getscriptinfo() source Xscript let l = getscriptinfo() call assert_match('Xscript$', l[-1].name) - " Nvim does not support interpolated strings yet. - " call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") - call assert_equal(g:loaded_script_id, '<SNR>' . l[-1].sid . '_') + call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_") call delete('Xscript') endfunc |