blob: dc3cb8919d94590bc1b5ac5e6aeb43f729d7b49e [file] [log] [blame]
Bram Moolenaarfabaf752017-12-23 17:26:11 +01001" Tests for various eval things.
2
3function s:foo() abort
4 try
5 return [] == 0
6 catch
7 return 1
8 endtry
9endfunction
10
11func Test_catch_return_with_error()
12 call assert_equal(1, s:foo())
13endfunc
Bram Moolenaar2be57332018-02-13 18:05:18 +010014
15func Test_nocatch_restore_silent_emsg()
16 silent! try
17 throw 1
18 catch
19 endtry
20 echoerr 'wrong'
21 let c1 = nr2char(screenchar(&lines, 1))
22 let c2 = nr2char(screenchar(&lines, 2))
23 let c3 = nr2char(screenchar(&lines, 3))
24 let c4 = nr2char(screenchar(&lines, 4))
25 let c5 = nr2char(screenchar(&lines, 5))
26 call assert_equal('wrong', c1 . c2 . c3 . c4 . c5)
27endfunc
Bram Moolenaar78a16b02018-04-14 13:51:55 +020028
29func Test_mkdir_p()
30 call mkdir('Xmkdir/nested', 'p')
31 call assert_true(isdirectory('Xmkdir/nested'))
32 try
33 " Trying to make existing directories doesn't error
34 call mkdir('Xmkdir', 'p')
35 call mkdir('Xmkdir/nested', 'p')
36 catch /E739:/
37 call assert_report('mkdir(..., "p") failed for an existing directory')
38 endtry
39 " 'p' doesn't suppress real errors
40 call writefile([], 'Xfile')
41 call assert_fails('call mkdir("Xfile", "p")', 'E739')
42 call delete('Xfile')
43 call delete('Xmkdir', 'rf')
44endfunc
Bram Moolenaar67f8ab82018-09-11 22:37:29 +020045
46func Test_line_continuation()
47 let array = [5,
48 "\ ignore this
49 \ 6,
50 "\ more to ignore
51 "\ more moreto ignore
52 \ ]
53 "\ and some more
54 call assert_equal([5, 6], array)
55endfunc
Bram Moolenaar88b53fd2018-12-05 18:43:28 +010056
57func Test_E963()
58 " These commands used to cause an internal error prior to vim 8.1.0563
59 let v_e = v:errors
60 let v_o = v:oldfiles
61 call assert_fails("let v:errors=''", 'E963:')
62 call assert_equal(v_e, v:errors)
63 call assert_fails("let v:oldfiles=''", 'E963:')
64 call assert_equal(v_o, v:oldfiles)
65endfunc
Bram Moolenaarc0f5a782019-01-13 15:16:13 +010066
67func Test_for_invalid()
68 call assert_fails("for x in 99", 'E714:')
69 call assert_fails("for x in 'asdf'", 'E714:')
70 call assert_fails("for x in {'a': 9}", 'E714:')
71endfunc