aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/old/testdir/test_debugger.vim33
-rw-r--r--test/old/testdir/test_expr.vim56
-rw-r--r--test/old/testdir/test_let.vim59
3 files changed, 124 insertions, 24 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_expr.vim b/test/old/testdir/test_expr.vim
index c8b7fde100..86e720a1ae 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\x7b123}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 915bba2314..8f7121935e 100644
--- a/test/old/testdir/test_let.vim
+++ b/test/old/testdir/test_let.vim
@@ -387,6 +387,17 @@ END
call assert_equal(['Text', 'with', 'indent'], text)
endfunc
+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 .. '{{'}")
+ " FIXME: should not need to escape quotes in the expression
+ 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()
@@ -496,72 +507,72 @@ END
call assert_equal([' x', ' \y', ' z'], [a, b, c])
endfunc
-" Test for evaluating Vim expressions in a heredoc using `=expr`
+" 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"
+ 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`"
+ let s = "{$TESTVAR}"
END
call assert_equal(['let s = "Hello"'], code)
let code =<< eval END
- let s = "`=$TESTVAR`"
+ let s = "{$TESTVAR}"
END
call assert_equal([' let s = "Hello"'], code)
let a = 10
let data =<< eval END
-`=a`
+{a}
END
call assert_equal(['10'], data)
let x = 'X'
let code =<< eval trim END
- let a = `abc`
- let b = `=x`
- let c = `
+ let a = {{abc}}
+ let b = {x}
+ let c = {{
END
- call assert_equal(['let a = `abc`', 'let b = X', 'let c = `'], code)
+ call assert_equal(['let a = {abc}', 'let b = X', 'let c = {'], code)
let code = 'xxx'
let code =<< eval trim END
- let n = `=5 +
- 6`
+ let n = {5 +
+ 6}
END
call assert_equal('xxx', code)
let code =<< eval trim END
- let n = `=min([1, 2]` + `=max([3, 4])`
+ 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 = `=
+ let b = {
END
LINES
- call CheckScriptFailure(lines, 'E1083:')
+ call CheckScriptFailure(lines, 'E1279:')
let lines =<< trim LINES
let text =<< eval trim END
- let b = `=abc
+ let b = {abc
END
LINES
- call CheckScriptFailure(lines, 'E1083:')
+ call CheckScriptFailure(lines, 'E1279:')
let lines =<< trim LINES
let text =<< eval trim END
- let b = `=`
+ let b = {}
END
LINES
call CheckScriptFailure(lines, 'E15:')
@@ -569,7 +580,7 @@ END
" skipped heredoc
if 0
let msg =<< trim eval END
- n is: `=n`
+ n is: {n}
END
endif
@@ -581,7 +592,7 @@ END
let lines =<< trim END
let Xvar =<< eval CODE
let a = 1
- let b = `=5+`
+ let b = {5+}
let c = 2
CODE
let g:Count += 1
@@ -590,10 +601,10 @@ END
let g:Count = 0
call assert_fails('source', 'E15:')
call assert_equal(1, g:Count)
- call setline(3, 'let b = `=abc`')
+ 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 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)