Mercurial > vim
comparison src/testdir/test_expand.vim @ 28283:2fd2ce8a556c v8.2.4667
patch 8.2.4667: expandcmd() fails on an error
Commit: https://github.com/vim/vim/commit/5018a836c030988944a9bbe2fd2e538bf5261a72
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Apr 2 21:12:21 2022 +0100
patch 8.2.4667: expandcmd() fails on an error
Problem: expandcmd() fails on an error.
Solution: On failure return the command unmodified. (yegappan Lakshmanan,
closes #10063)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 Apr 2022 22:15:03 +0200 |
parents | 9865f996a3c0 |
children | 425700af491b |
comparison
equal
deleted
inserted
replaced
28282:548b4ab77157 | 28283:2fd2ce8a556c |
---|---|
76 call assert_equal('make abc.java', expandcmd('make abc.%:e')) | 76 call assert_equal('make abc.java', expandcmd('make abc.%:e')) |
77 call assert_equal('make Xabc.java', expandcmd('make %:s?file?abc?')) | 77 call assert_equal('make Xabc.java', expandcmd('make %:s?file?abc?')) |
78 edit a1a2a3.rb | 78 edit a1a2a3.rb |
79 call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) | 79 call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) |
80 | 80 |
81 call assert_fails('call expandcmd("make <afile>")', 'E495:') | 81 call assert_equal('make <afile>', expandcmd("make <afile>")) |
82 call assert_fails('call expandcmd("make <afile>")', 'E495:') | 82 call assert_equal('make <amatch>', expandcmd("make <amatch>")) |
83 call assert_equal('make <abuf>', expandcmd("make <abuf>")) | |
83 enew | 84 enew |
84 call assert_fails('call expandcmd("make %")', 'E499:') | 85 call assert_equal('make %', expandcmd("make %")) |
85 let $FOO="blue\tsky" | 86 let $FOO="blue\tsky" |
86 call setline(1, "$FOO") | 87 call setline(1, "$FOO") |
87 call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>')) | 88 call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>')) |
88 | 89 |
89 " Test for expression expansion `= | 90 " Test for expression expansion `= |
92 | 93 |
93 " Test for env variable with spaces | 94 " Test for env variable with spaces |
94 let $FOO= "foo bar baz" | 95 let $FOO= "foo bar baz" |
95 call assert_equal("e foo bar baz", expandcmd("e $FOO")) | 96 call assert_equal("e foo bar baz", expandcmd("e $FOO")) |
96 | 97 |
98 if has('unix') | |
99 " test for using the shell to expand a command argument | |
100 call assert_equal('{1..4}', expandcmd('{1..4}')) | |
101 endif | |
102 | |
97 unlet $FOO | 103 unlet $FOO |
98 close! | 104 close! |
99 endfunc | 105 endfunc |
100 | 106 |
101 " Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script | 107 " Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script |
102 func Test_source_sfile() | 108 func Test_source_sfile() |
103 let lines =<< trim [SCRIPT] | 109 let lines =<< trim [SCRIPT] |
104 :call assert_fails('echo expandcmd("<sfile>")', 'E498:') | 110 :call assert_equal('<sfile>', expandcmd("<sfile>")) |
105 :call assert_fails('echo expandcmd("<slnum>")', 'E842:') | 111 :call assert_equal('<slnum>', expandcmd("<slnum>")) |
106 :call assert_fails('echo expandcmd("<sflnum>")', 'E961:') | 112 :call assert_equal('<sflnum>', expandcmd("<sflnum>")) |
107 :call assert_fails('call expandcmd("edit <cfile>")', 'E446:') | 113 :call assert_equal('edit <cfile>', expandcmd("edit <cfile>")) |
108 :call assert_fails('call expandcmd("edit #")', 'E194:') | 114 :call assert_equal('edit #', expandcmd("edit #")) |
109 :call assert_fails('call expandcmd("edit #<2")', 'E684:') | 115 :call assert_equal('edit #<2', expandcmd("edit #<2")) |
110 :call assert_fails('call expandcmd("edit <cword>")', 'E348:') | 116 :call assert_equal('edit <cword>', expandcmd("edit <cword>")) |
111 :call assert_fails('call expandcmd("edit <cexpr>")', 'E348:') | 117 :call assert_equal('edit <cexpr>', expandcmd("edit <cexpr>")) |
112 :call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:') | 118 :call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:') |
113 :call writefile(v:errors, 'Xresult') | 119 :call writefile(v:errors, 'Xresult') |
114 :qall! | 120 :qall! |
115 | 121 |
116 [SCRIPT] | 122 [SCRIPT] |