1" 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 14 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 28 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 45 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 56 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 66 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 72 73func Test_readfile_binary() 74 new 75 call setline(1, ['one', 'two', 'three']) 76 setlocal ff=dos 77 silent write XReadfile 78 let lines = 'XReadfile'->readfile() 79 call assert_equal(['one', 'two', 'three'], lines) 80 let lines = readfile('XReadfile', '', 2) 81 call assert_equal(['one', 'two'], lines) 82 let lines = readfile('XReadfile', 'b') 83 call assert_equal(["one\r", "two\r", "three\r", ""], lines) 84 let lines = readfile('XReadfile', 'b', 2) 85 call assert_equal(["one\r", "two\r"], lines) 86 87 bwipe! 88 call delete('XReadfile') 89endfunc 90 91func Test_let_errmsg() 92 call assert_fails('let v:errmsg = []', 'E730:') 93 let v:errmsg = '' 94 call assert_fails('let v:errmsg = []', 'E730:') 95 let v:errmsg = '' 96endfunc 97 98func Test_string_concatenation() 99 call assert_equal('ab', 'a'.'b') 100 call assert_equal('ab', 'a' .'b') 101 call assert_equal('ab', 'a'. 'b') 102 call assert_equal('ab', 'a' . 'b') 103 104 call assert_equal('ab', 'a'..'b') 105 call assert_equal('ab', 'a' ..'b') 106 call assert_equal('ab', 'a'.. 'b') 107 call assert_equal('ab', 'a' .. 'b') 108 109 let a = 'a' 110 let b = 'b' 111 let a .= b 112 call assert_equal('ab', a) 113 114 let a = 'a' 115 let a.=b 116 call assert_equal('ab', a) 117 118 let a = 'a' 119 let a ..= b 120 call assert_equal('ab', a) 121 122 let a = 'a' 123 let a..=b 124 call assert_equal('ab', a) 125endfunc 126 127" Test fix for issue #4507 128func Test_skip_after_throw() 129 try 130 throw 'something' 131 let x = wincol() || &ts 132 catch /something/ 133 endtry 134endfunc 135 136scriptversion 2 137func Test_string_concat_scriptversion2() 138 call assert_true(has('vimscript-2')) 139 let a = 'a' 140 let b = 'b' 141 142 call assert_fails('echo a . b', 'E15:') 143 call assert_fails('let a .= b', 'E985:') 144 call assert_fails('let vers = 1.2.3', 'E15:') 145 146 if has('float') 147 let f = .5 148 call assert_equal(0.5, f) 149 endif 150endfunc 151 152scriptversion 1 153func Test_string_concat_scriptversion1() 154 call assert_true(has('vimscript-1')) 155 let a = 'a' 156 let b = 'b' 157 158 echo a . b 159 let a .= b 160 let vers = 1.2.3 161 call assert_equal('123', vers) 162 163 if has('float') 164 call assert_fails('let f = .5', 'E15:') 165 endif 166endfunc 167 168scriptversion 3 169func Test_vvar_scriptversion3() 170 call assert_true(has('vimscript-3')) 171 call assert_fails('echo version', 'E121:') 172 call assert_false(exists('version')) 173 let version = 1 174 call assert_equal(1, version) 175endfunc 176 177scriptversion 2 178func Test_vvar_scriptversion2() 179 call assert_true(exists('version')) 180 echo version 181 call assert_fails('let version = 1', 'E46:') 182 call assert_equal(v:version, version) 183 184 call assert_equal(v:version, v:versionlong / 10000) 185 call assert_true(v:versionlong > 8011525) 186endfunc 187 188func Test_dict_access_scriptversion2() 189 let l:x = {'foo': 1} 190 191 call assert_false(0 && l:x.foo) 192 call assert_true(1 && l:x.foo) 193endfunc 194 195scriptversion 4 196func Test_vvar_scriptversion4() 197 call assert_true(has('vimscript-4')) 198 call assert_equal(17, 017) 199 call assert_equal(18, 018) 200 call assert_equal(64, 0b1'00'00'00) 201 call assert_equal(1048576, 0x10'00'00) 202 call assert_equal(1000000, 1'000'000) 203 call assert_equal("1234", execute("echo 1'234")->trim()) 204 call assert_equal('1 234', execute("echo 1''234")->trim()) 205 call assert_fails("echo 1'''234", 'E115:') 206endfunc 207 208scriptversion 1 209func Test_vvar_scriptversion1() 210 call assert_equal(15, 017) 211 call assert_equal(18, 018) 212endfunc 213 214func Test_scriptversion_fail() 215 call writefile(['scriptversion 9'], 'Xversionscript') 216 call assert_fails('source Xversionscript', 'E999:') 217 call delete('Xversionscript') 218endfunc 219 220func Test_excute_null() 221 call assert_fails('execute test_null_list()', 'E730:') 222 call assert_fails('execute test_null_dict()', 'E731:') 223 call assert_fails('execute test_null_blob()', 'E976:') 224 execute test_null_string() 225 call assert_fails('execute test_null_partial()', 'E729:') 226 if has('job') 227 call assert_fails('execute test_null_job()', 'E908:') 228 call assert_fails('execute test_null_channel()', 'E908:') 229 endif 230endfunc 231 232func Test_numbersize() 233 " This will fail on systems without 64 bit int support or when not configured 234 " correctly. 235 call assert_equal(64, v:numbersize) 236endfunc 237 238" vim: shiftwidth=2 sts=2 expandtab 239