diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 19:46:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-15 19:46:17 +0800 |
commit | 62b7b1daf37abbe4d72838933569fefa970aa2e4 (patch) | |
tree | 3e04748f05198e3e971e386bf6270cbc65d79413 /test/old/testdir/test_expr.vim | |
parent | 071c455420dec7992a06a55e8bd443b769ded369 (diff) | |
parent | 57221e0d11d1c24bc2abada7559a1d20c5090b62 (diff) | |
download | rneovim-62b7b1daf37abbe4d72838933569fefa970aa2e4.tar.gz rneovim-62b7b1daf37abbe4d72838933569fefa970aa2e4.tar.bz2 rneovim-62b7b1daf37abbe4d72838933569fefa970aa2e4.zip |
Merge pull request #23105 from zeertzjq/vim-8.2.4770
vim-patch:8.2.{4770,4783,4840,4883,4930,4934},9.0.0104: interpolated string
Diffstat (limited to 'test/old/testdir/test_expr.vim')
-rw-r--r-- | test/old/testdir/test_expr.vim | 56 |
1 files changed, 56 insertions, 0 deletions
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 |