Mercurial > vim
comparison src/testdir/test_let.vim @ 19689:da98d2ed8dc5 v8.2.0401
patch 8.2.0401: not enough test coverage for evalvars.c
Commit: https://github.com/vim/vim/commit/8dfcce3a78ccb520cc9d09081f998091494c50bf
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 18 19:32:26 2020 +0100
patch 8.2.0401: not enough test coverage for evalvars.c
Problem: Not enough test coverage for evalvars.c.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5804)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Mar 2020 19:45:04 +0100 |
parents | baf890fa1621 |
children | b3e93a05c3ca |
comparison
equal
deleted
inserted
replaced
19688:8d01c76e0bc7 | 19689:da98d2ed8dc5 |
---|---|
23 | 23 |
24 let out = execute('let a {0 == 1 ? "a" : "b"}') | 24 let out = execute('let a {0 == 1 ? "a" : "b"}') |
25 let s = "\na #1\nb #2" | 25 let s = "\na #1\nb #2" |
26 call assert_equal(s, out) | 26 call assert_equal(s, out) |
27 | 27 |
28 " Test for displaying a string variable | |
29 let s = 'vim' | |
30 let out = execute('let s') | |
31 let s = "\ns vim" | |
32 call assert_equal(s, out) | |
33 | |
34 " Test for displaying a list variable | |
35 let l = [1, 2] | |
36 let out = execute('let l') | |
37 let s = "\nl [1, 2]" | |
38 call assert_equal(s, out) | |
39 | |
40 " Test for displaying a dict variable | |
41 let d = {'k' : 'v'} | |
42 let out = execute('let d') | |
43 let s = "\nd {'k': 'v'}" | |
44 call assert_equal(s, out) | |
45 | |
46 " Test for displaying a function reference variable | |
47 let F = function('min') | |
48 let out = execute('let F') | |
49 let s = "\nF *min()" | |
50 call assert_equal(s, out) | |
51 | |
28 let x = 0 | 52 let x = 0 |
29 if 0 | let x = 1 | endif | 53 if 0 | let x = 1 | endif |
30 call assert_equal(0, x) | 54 call assert_equal(0, x) |
55 | |
56 " Display a list item using an out of range index | |
57 let l = [10] | |
58 call assert_fails('let l[1]', 'E684:') | |
59 | |
60 " List special variable dictionaries | |
61 let g:Test_Global_Var = 5 | |
62 call assert_match("\nTest_Global_Var #5", execute('let g:')) | |
63 unlet g:Test_Global_Var | |
64 | |
65 let b:Test_Buf_Var = 8 | |
66 call assert_match("\nb:Test_Buf_Var #8", execute('let b:')) | |
67 unlet b:Test_Buf_Var | |
68 | |
69 let w:Test_Win_Var = 'foo' | |
70 call assert_equal("\nw:Test_Win_Var foo", execute('let w:')) | |
71 unlet w:Test_Win_Var | |
72 | |
73 let t:Test_Tab_Var = 'bar' | |
74 call assert_equal("\nt:Test_Tab_Var bar", execute('let t:')) | |
75 unlet t:Test_Tab_Var | |
76 | |
77 let s:Test_Script_Var = [7] | |
78 call assert_match("\ns:Test_Script_Var \\[7]", execute('let s:')) | |
79 unlet s:Test_Script_Var | |
80 | |
81 let l:Test_Local_Var = {'k' : 5} | |
82 call assert_match("\nl:Test_Local_Var {'k': 5}", execute('let l:')) | |
83 call assert_match("v:errors []", execute('let v:')) | |
31 endfunc | 84 endfunc |
32 | 85 |
33 func s:set_arg1(a) abort | 86 func s:set_arg1(a) abort |
34 let a:a = 1 | 87 let a:a = 1 |
35 endfunction | 88 endfunction |
198 call assert_fails('let &fillchars += "diff:-"', 'E734') | 251 call assert_fails('let &fillchars += "diff:-"', 'E734') |
199 call assert_equal("vert:|", &fillchars) | 252 call assert_equal("vert:|", &fillchars) |
200 let &fillchars = _w | 253 let &fillchars = _w |
201 endfunc | 254 endfunc |
202 | 255 |
256 " Errors with the :let statement | |
203 func Test_let_errors() | 257 func Test_let_errors() |
204 let s = 'abcd' | 258 let s = 'abcd' |
205 call assert_fails('let s[1] = 5', 'E689:') | 259 call assert_fails('let s[1] = 5', 'E689:') |
206 | 260 |
207 let l = [1, 2, 3] | 261 let l = [1, 2, 3] |
208 call assert_fails('let l[:] = 5', 'E709:') | 262 call assert_fails('let l[:] = 5', 'E709:') |
263 | |
264 call assert_fails('let x:lnum=5', 'E488:') | |
265 call assert_fails('let v:=5', 'E461:') | |
266 call assert_fails('let [a]', 'E474:') | |
267 call assert_fails('let [a, b] = [', 'E697:') | |
268 call assert_fails('let [a, b] = [10, 20', 'E696:') | |
269 call assert_fails('let [a, b] = 10', 'E714:') | |
270 call assert_fails('let [a, , b] = [10, 20]', 'E475:') | |
271 call assert_fails('let [a, b&] = [10, 20]', 'E475:') | |
272 call assert_fails('let $ = 10', 'E475:') | |
273 call assert_fails('let $FOO[1] = "abc"', 'E18:') | |
274 call assert_fails('let &buftype[1] = "nofile"', 'E18:') | |
275 let s = "var" | |
276 let var = 1 | |
277 call assert_fails('let {s}.1 = 2', 'E18:') | |
278 | |
279 " This test works only when the language is English | |
280 if v:lang == "C" || v:lang =~ '^[Ee]n' | |
281 call assert_fails('let [a ; b;] = [10, 20]', | |
282 \ 'Double ; in list of variables') | |
283 endif | |
209 endfunc | 284 endfunc |
210 | 285 |
211 func Test_let_heredoc_fails() | 286 func Test_let_heredoc_fails() |
212 call assert_fails('let v =<< marker', 'E991:') | 287 call assert_fails('let v =<< marker', 'E991:') |
288 try | |
289 exe "let v =<< TEXT | abc | TEXT" | |
290 call assert_report('No exception thrown') | |
291 catch /E488:/ | |
292 catch | |
293 call assert_report("Caught exception: " .. v:exception) | |
294 endtry | |
213 | 295 |
214 let text =<< trim END | 296 let text =<< trim END |
215 func WrongSyntax() | 297 func WrongSyntax() |
216 let v =<< that there | 298 let v =<< that there |
217 endfunc | 299 endfunc |
240 let v =<< text | 322 let v =<< text |
241 TEXTend | 323 TEXTend |
242 call writefile(text, 'XheredocBadMarker') | 324 call writefile(text, 'XheredocBadMarker') |
243 call assert_fails('source XheredocBadMarker', 'E221:') | 325 call assert_fails('source XheredocBadMarker', 'E221:') |
244 call delete('XheredocBadMarker') | 326 call delete('XheredocBadMarker') |
327 | |
328 call writefile(['let v =<< TEXT', 'abc'], 'XheredocMissingMarker') | |
329 call assert_fails('source XheredocMissingMarker', 'E990:') | |
330 call delete('XheredocMissingMarker') | |
245 endfunc | 331 endfunc |
246 | 332 |
247 func Test_let_heredoc_trim_no_indent_marker() | 333 func Test_let_heredoc_trim_no_indent_marker() |
248 let text =<< trim END | 334 let text =<< trim END |
249 Text | 335 Text |
366 \y | 452 \y |
367 z | 453 z |
368 END | 454 END |
369 call assert_equal([' x', ' \y', ' z'], [a, b, c]) | 455 call assert_equal([' x', ' \y', ' z'], [a, b, c]) |
370 endfunc | 456 endfunc |
457 | |
458 " vim: shiftwidth=2 sts=2 expandtab |