Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 1 | " Tests for various functions. |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 2 | source shared.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 4 | |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 5 | " Must be done first, since the alternate buffer must be unset. |
| 6 | func Test_00_bufexists() |
| 7 | call assert_equal(0, bufexists('does_not_exist')) |
| 8 | call assert_equal(1, bufexists(bufnr('%'))) |
| 9 | call assert_equal(0, bufexists(0)) |
| 10 | new Xfoo |
| 11 | let bn = bufnr('%') |
| 12 | call assert_equal(1, bufexists(bn)) |
| 13 | call assert_equal(1, bufexists('Xfoo')) |
| 14 | call assert_equal(1, bufexists(getcwd() . '/Xfoo')) |
| 15 | call assert_equal(1, bufexists(0)) |
| 16 | bw |
| 17 | call assert_equal(0, bufexists(bn)) |
| 18 | call assert_equal(0, bufexists('Xfoo')) |
| 19 | endfunc |
| 20 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 21 | func Test_empty() |
| 22 | call assert_equal(1, empty('')) |
| 23 | call assert_equal(0, empty('a')) |
| 24 | |
| 25 | call assert_equal(1, empty(0)) |
| 26 | call assert_equal(1, empty(-0)) |
| 27 | call assert_equal(0, empty(1)) |
| 28 | call assert_equal(0, empty(-1)) |
| 29 | |
| 30 | call assert_equal(1, empty(0.0)) |
| 31 | call assert_equal(1, empty(-0.0)) |
| 32 | call assert_equal(0, empty(1.0)) |
| 33 | call assert_equal(0, empty(-1.0)) |
| 34 | call assert_equal(0, empty(1.0/0.0)) |
| 35 | call assert_equal(0, empty(0.0/0.0)) |
| 36 | |
| 37 | call assert_equal(1, empty([])) |
| 38 | call assert_equal(0, empty(['a'])) |
| 39 | |
| 40 | call assert_equal(1, empty({})) |
| 41 | call assert_equal(0, empty({'a':1})) |
| 42 | |
| 43 | call assert_equal(1, empty(v:null)) |
| 44 | call assert_equal(1, empty(v:none)) |
| 45 | call assert_equal(1, empty(v:false)) |
| 46 | call assert_equal(0, empty(v:true)) |
| 47 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 48 | if has('channel') |
| 49 | call assert_equal(1, empty(test_null_channel())) |
| 50 | endif |
| 51 | if has('job') |
| 52 | call assert_equal(1, empty(test_null_job())) |
| 53 | endif |
| 54 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 55 | call assert_equal(0, empty(function('Test_empty'))) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 56 | call assert_equal(0, empty(function('Test_empty', [0]))) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 57 | endfunc |
| 58 | |
| 59 | func Test_len() |
| 60 | call assert_equal(1, len(0)) |
| 61 | call assert_equal(2, len(12)) |
| 62 | |
| 63 | call assert_equal(0, len('')) |
| 64 | call assert_equal(2, len('ab')) |
| 65 | |
| 66 | call assert_equal(0, len([])) |
| 67 | call assert_equal(2, len([2, 1])) |
| 68 | |
| 69 | call assert_equal(0, len({})) |
| 70 | call assert_equal(2, len({'a': 1, 'b': 2})) |
| 71 | |
| 72 | call assert_fails('call len(v:none)', 'E701:') |
| 73 | call assert_fails('call len({-> 0})', 'E701:') |
| 74 | endfunc |
| 75 | |
| 76 | func Test_max() |
| 77 | call assert_equal(0, max([])) |
| 78 | call assert_equal(2, max([2])) |
| 79 | call assert_equal(2, max([1, 2])) |
| 80 | call assert_equal(2, max([1, 2, v:null])) |
| 81 | |
| 82 | call assert_equal(0, max({})) |
| 83 | call assert_equal(2, max({'a':1, 'b':2})) |
| 84 | |
| 85 | call assert_fails('call max(1)', 'E712:') |
| 86 | call assert_fails('call max(v:none)', 'E712:') |
| 87 | endfunc |
| 88 | |
| 89 | func Test_min() |
| 90 | call assert_equal(0, min([])) |
| 91 | call assert_equal(2, min([2])) |
| 92 | call assert_equal(1, min([1, 2])) |
| 93 | call assert_equal(0, min([1, 2, v:null])) |
| 94 | |
| 95 | call assert_equal(0, min({})) |
| 96 | call assert_equal(1, min({'a':1, 'b':2})) |
| 97 | |
| 98 | call assert_fails('call min(1)', 'E712:') |
| 99 | call assert_fails('call min(v:none)', 'E712:') |
| 100 | endfunc |
| 101 | |
Bram Moolenaar | 42ab17b | 2018-05-20 14:11:10 +0200 | [diff] [blame] | 102 | func Test_strwidth() |
| 103 | for aw in ['single', 'double'] |
| 104 | exe 'set ambiwidth=' . aw |
| 105 | call assert_equal(0, strwidth('')) |
| 106 | call assert_equal(1, strwidth("\t")) |
| 107 | call assert_equal(3, strwidth('Vim')) |
| 108 | call assert_equal(4, strwidth(1234)) |
| 109 | call assert_equal(5, strwidth(-1234)) |
| 110 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 111 | call assert_equal(2, strwidth('😉')) |
| 112 | call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde')) |
| 113 | call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße')) |
Bram Moolenaar | 42ab17b | 2018-05-20 14:11:10 +0200 | [diff] [blame] | 114 | |
| 115 | call assert_fails('call strwidth({->0})', 'E729:') |
| 116 | call assert_fails('call strwidth([])', 'E730:') |
| 117 | call assert_fails('call strwidth({})', 'E731:') |
| 118 | call assert_fails('call strwidth(1.2)', 'E806:') |
| 119 | endfor |
| 120 | |
| 121 | set ambiwidth& |
| 122 | endfunc |
| 123 | |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 124 | func Test_str2nr() |
| 125 | call assert_equal(0, str2nr('')) |
| 126 | call assert_equal(1, str2nr('1')) |
| 127 | call assert_equal(1, str2nr(' 1 ')) |
| 128 | |
| 129 | call assert_equal(1, str2nr('+1')) |
| 130 | call assert_equal(1, str2nr('+ 1')) |
| 131 | call assert_equal(1, str2nr(' + 1 ')) |
| 132 | |
| 133 | call assert_equal(-1, str2nr('-1')) |
| 134 | call assert_equal(-1, str2nr('- 1')) |
| 135 | call assert_equal(-1, str2nr(' - 1 ')) |
| 136 | |
| 137 | call assert_equal(123456789, str2nr('123456789')) |
| 138 | call assert_equal(-123456789, str2nr('-123456789')) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 139 | |
| 140 | call assert_equal(5, str2nr('101', 2)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 141 | call assert_equal(5, '0b101'->str2nr(2)) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 142 | call assert_equal(5, str2nr('0B101', 2)) |
| 143 | call assert_equal(-5, str2nr('-101', 2)) |
| 144 | call assert_equal(-5, str2nr('-0b101', 2)) |
| 145 | call assert_equal(-5, str2nr('-0B101', 2)) |
| 146 | |
| 147 | call assert_equal(65, str2nr('101', 8)) |
| 148 | call assert_equal(65, str2nr('0101', 8)) |
| 149 | call assert_equal(-65, str2nr('-101', 8)) |
| 150 | call assert_equal(-65, str2nr('-0101', 8)) |
| 151 | |
| 152 | call assert_equal(11259375, str2nr('abcdef', 16)) |
| 153 | call assert_equal(11259375, str2nr('ABCDEF', 16)) |
| 154 | call assert_equal(-11259375, str2nr('-ABCDEF', 16)) |
| 155 | call assert_equal(11259375, str2nr('0xabcdef', 16)) |
| 156 | call assert_equal(11259375, str2nr('0Xabcdef', 16)) |
| 157 | call assert_equal(11259375, str2nr('0XABCDEF', 16)) |
| 158 | call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) |
| 159 | |
Bram Moolenaar | 60a8de2 | 2019-09-15 14:33:22 +0200 | [diff] [blame] | 160 | call assert_equal(1, str2nr("1'000'000", 10, 0)) |
| 161 | call assert_equal(256, str2nr("1'0000'0000", 2, 1)) |
| 162 | call assert_equal(262144, str2nr("1'000'000", 8, 1)) |
| 163 | call assert_equal(1000000, str2nr("1'000'000", 10, 1)) |
| 164 | call assert_equal(65536, str2nr("1'00'00", 16, 1)) |
| 165 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 166 | call assert_equal(0, str2nr('0x10')) |
| 167 | call assert_equal(0, str2nr('0b10')) |
| 168 | call assert_equal(1, str2nr('12', 2)) |
| 169 | call assert_equal(1, str2nr('18', 8)) |
| 170 | call assert_equal(1, str2nr('1g', 16)) |
| 171 | |
| 172 | call assert_equal(0, str2nr(v:null)) |
| 173 | call assert_equal(0, str2nr(v:none)) |
| 174 | |
| 175 | call assert_fails('call str2nr([])', 'E730:') |
| 176 | call assert_fails('call str2nr({->2})', 'E729:') |
| 177 | call assert_fails('call str2nr(1.2)', 'E806:') |
| 178 | call assert_fails('call str2nr(10, [])', 'E474:') |
| 179 | endfunc |
| 180 | |
| 181 | func Test_strftime() |
| 182 | if !exists('*strftime') |
| 183 | return |
| 184 | endif |
| 185 | " Format of strftime() depends on system. We assume |
| 186 | " that basic formats tested here are available and |
| 187 | " identical on all systems which support strftime(). |
| 188 | " |
| 189 | " The 2nd parameter of strftime() is a local time, so the output day |
| 190 | " of strftime() can be 17 or 18, depending on timezone. |
| 191 | call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) |
| 192 | " |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 193 | call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', '%Y-%m-%d %H:%M:%S'->strftime()) |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 194 | |
| 195 | call assert_fails('call strftime([])', 'E730:') |
| 196 | call assert_fails('call strftime("%Y", [])', 'E745:') |
Bram Moolenaar | db51730 | 2019-06-18 22:53:24 +0200 | [diff] [blame] | 197 | |
| 198 | " Check that the time changes after we change the timezone |
| 199 | " Save previous timezone value, if any |
| 200 | if exists('$TZ') |
| 201 | let tz = $TZ |
| 202 | endif |
| 203 | |
| 204 | " Force EST and then UTC, save the current hour (24-hour clock) for each |
| 205 | let $TZ = 'EST' | let est = strftime('%H') |
| 206 | let $TZ = 'UTC' | let utc = strftime('%H') |
| 207 | |
| 208 | " Those hours should be two bytes long, and should not be the same; if they |
| 209 | " are, a tzset(3) call may have failed somewhere |
| 210 | call assert_equal(strlen(est), 2) |
| 211 | call assert_equal(strlen(utc), 2) |
Bram Moolenaar | 87652a7 | 2019-06-18 23:07:37 +0200 | [diff] [blame] | 212 | " TODO: this fails on MS-Windows |
| 213 | if has('unix') |
| 214 | call assert_notequal(est, utc) |
| 215 | endif |
Bram Moolenaar | db51730 | 2019-06-18 22:53:24 +0200 | [diff] [blame] | 216 | |
| 217 | " If we cached a timezone value, put it back, otherwise clear it |
| 218 | if exists('tz') |
| 219 | let $TZ = tz |
| 220 | else |
| 221 | unlet $TZ |
| 222 | endif |
| 223 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 224 | endfunc |
| 225 | |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 226 | func Test_resolve_unix() |
Bram Moolenaar | 2610990 | 2018-10-06 15:43:17 +0200 | [diff] [blame] | 227 | if !has('unix') |
| 228 | return |
| 229 | endif |
| 230 | |
| 231 | " Xlink1 -> Xlink2 |
| 232 | " Xlink2 -> Xlink3 |
| 233 | silent !ln -s -f Xlink2 Xlink1 |
| 234 | silent !ln -s -f Xlink3 Xlink2 |
| 235 | call assert_equal('Xlink3', resolve('Xlink1')) |
| 236 | call assert_equal('./Xlink3', resolve('./Xlink1')) |
| 237 | call assert_equal('Xlink3/', resolve('Xlink2/')) |
| 238 | " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?! |
| 239 | "call assert_equal('Xlink3/', resolve('Xlink1/')) |
| 240 | "call assert_equal('./Xlink3/', resolve('./Xlink1/')) |
| 241 | "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/')) |
| 242 | call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1')) |
| 243 | |
| 244 | " Test resolve() with a symlink cycle. |
| 245 | " Xlink1 -> Xlink2 |
| 246 | " Xlink2 -> Xlink3 |
| 247 | " Xlink3 -> Xlink1 |
| 248 | silent !ln -s -f Xlink1 Xlink3 |
| 249 | call assert_fails('call resolve("Xlink1")', 'E655:') |
| 250 | call assert_fails('call resolve("./Xlink1")', 'E655:') |
| 251 | call assert_fails('call resolve("Xlink2")', 'E655:') |
| 252 | call assert_fails('call resolve("Xlink3")', 'E655:') |
| 253 | call delete('Xlink1') |
| 254 | call delete('Xlink2') |
| 255 | call delete('Xlink3') |
| 256 | |
| 257 | silent !ln -s -f Xdir//Xfile Xlink |
| 258 | call assert_equal('Xdir/Xfile', resolve('Xlink')) |
| 259 | call delete('Xlink') |
| 260 | |
| 261 | silent !ln -s -f Xlink2/ Xlink1 |
Bram Moolenaar | a0d1fef | 2019-09-04 22:29:14 +0200 | [diff] [blame] | 262 | call assert_equal('Xlink2', 'Xlink1'->resolve()) |
Bram Moolenaar | 2610990 | 2018-10-06 15:43:17 +0200 | [diff] [blame] | 263 | call assert_equal('Xlink2/', resolve('Xlink1/')) |
| 264 | call delete('Xlink1') |
| 265 | |
| 266 | silent !ln -s -f ./Xlink2 Xlink1 |
| 267 | call assert_equal('Xlink2', resolve('Xlink1')) |
| 268 | call assert_equal('./Xlink2', resolve('./Xlink1')) |
| 269 | call delete('Xlink1') |
| 270 | endfunc |
| 271 | |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 272 | func s:normalize_fname(fname) |
| 273 | let ret = substitute(a:fname, '\', '/', 'g') |
| 274 | let ret = substitute(ret, '//', '/', 'g') |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 275 | return ret->tolower() |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 276 | endfunc |
| 277 | |
| 278 | func Test_resolve_win32() |
| 279 | if !has('win32') |
| 280 | return |
| 281 | endif |
| 282 | |
| 283 | " test for shortcut file |
| 284 | if executable('cscript') |
| 285 | new Xfile |
| 286 | wq |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 287 | let lines =<< trim END |
| 288 | Set fs = CreateObject("Scripting.FileSystemObject") |
| 289 | Set ws = WScript.CreateObject("WScript.Shell") |
| 290 | Set shortcut = ws.CreateShortcut("Xlink.lnk") |
| 291 | shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile") |
| 292 | shortcut.Save |
| 293 | END |
| 294 | call writefile(lines, 'link.vbs') |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 295 | silent !cscript link.vbs |
| 296 | call delete('link.vbs') |
| 297 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) |
| 298 | call delete('Xfile') |
| 299 | |
| 300 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk'))) |
| 301 | call delete('Xlink.lnk') |
| 302 | else |
| 303 | echomsg 'skipped test for shortcut file' |
| 304 | endif |
| 305 | |
| 306 | " remove files |
| 307 | call delete('Xlink') |
| 308 | call delete('Xdir', 'd') |
| 309 | call delete('Xfile') |
| 310 | |
| 311 | " test for symbolic link to a file |
| 312 | new Xfile |
| 313 | wq |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 314 | call assert_equal('Xfile', resolve('Xfile')) |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 315 | silent !mklink Xlink Xfile |
| 316 | if !v:shell_error |
| 317 | call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink'))) |
| 318 | call delete('Xlink') |
| 319 | else |
| 320 | echomsg 'skipped test for symbolic link to a file' |
| 321 | endif |
| 322 | call delete('Xfile') |
| 323 | |
| 324 | " test for junction to a directory |
| 325 | call mkdir('Xdir') |
| 326 | silent !mklink /J Xlink Xdir |
| 327 | if !v:shell_error |
| 328 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 329 | |
| 330 | call delete('Xdir', 'd') |
| 331 | |
| 332 | " test for junction already removed |
| 333 | call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 334 | call delete('Xlink') |
| 335 | else |
| 336 | echomsg 'skipped test for junction to a directory' |
| 337 | call delete('Xdir', 'd') |
| 338 | endif |
| 339 | |
| 340 | " test for symbolic link to a directory |
| 341 | call mkdir('Xdir') |
| 342 | silent !mklink /D Xlink Xdir |
| 343 | if !v:shell_error |
| 344 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 345 | |
| 346 | call delete('Xdir', 'd') |
| 347 | |
| 348 | " test for symbolic link already removed |
| 349 | call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink'))) |
| 350 | call delete('Xlink') |
| 351 | else |
| 352 | echomsg 'skipped test for symbolic link to a directory' |
| 353 | call delete('Xdir', 'd') |
| 354 | endif |
| 355 | |
| 356 | " test for buffer name |
| 357 | new Xfile |
| 358 | wq |
| 359 | silent !mklink Xlink Xfile |
| 360 | if !v:shell_error |
| 361 | edit Xlink |
| 362 | call assert_equal('Xlink', bufname('%')) |
| 363 | call delete('Xlink') |
| 364 | bw! |
| 365 | else |
| 366 | echomsg 'skipped test for buffer name' |
| 367 | endif |
| 368 | call delete('Xfile') |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 369 | |
| 370 | " test for reparse point |
| 371 | call mkdir('Xdir') |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 372 | call assert_equal('Xdir', resolve('Xdir')) |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 373 | silent !mklink /D Xdirlink Xdir |
| 374 | if !v:shell_error |
| 375 | w Xdir/text.txt |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 376 | call assert_equal('Xdir/text.txt', resolve('Xdir/text.txt')) |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 377 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir\text.txt'), s:normalize_fname(resolve('Xdirlink\text.txt'))) |
| 378 | call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve('Xdirlink'))) |
Bram Moolenaar | 4a792c8 | 2019-06-06 12:22:41 +0200 | [diff] [blame] | 379 | call delete('Xdirlink') |
Bram Moolenaar | 1bbebab | 2019-05-29 20:36:54 +0200 | [diff] [blame] | 380 | else |
| 381 | echomsg 'skipped test for reparse point' |
| 382 | endif |
| 383 | |
| 384 | call delete('Xdir', 'rf') |
Bram Moolenaar | dce1e89 | 2019-02-10 23:18:53 +0100 | [diff] [blame] | 385 | endfunc |
| 386 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 387 | func Test_simplify() |
| 388 | call assert_equal('', simplify('')) |
| 389 | call assert_equal('/', simplify('/')) |
| 390 | call assert_equal('/', simplify('/.')) |
| 391 | call assert_equal('/', simplify('/..')) |
| 392 | call assert_equal('/...', simplify('/...')) |
| 393 | call assert_equal('./dir/file', simplify('./dir/file')) |
| 394 | call assert_equal('./dir/file', simplify('.///dir//file')) |
| 395 | call assert_equal('./dir/file', simplify('./dir/./file')) |
| 396 | call assert_equal('./file', simplify('./dir/../file')) |
| 397 | call assert_equal('../dir/file', simplify('dir/../../dir/file')) |
| 398 | call assert_equal('./file', simplify('dir/.././file')) |
| 399 | |
| 400 | call assert_fails('call simplify({->0})', 'E729:') |
| 401 | call assert_fails('call simplify([])', 'E730:') |
| 402 | call assert_fails('call simplify({})', 'E731:') |
| 403 | call assert_fails('call simplify(1.2)', 'E806:') |
Bram Moolenaar | 08243d2 | 2017-01-10 16:12:29 +0100 | [diff] [blame] | 404 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 405 | |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 406 | func Test_pathshorten() |
| 407 | call assert_equal('', pathshorten('')) |
| 408 | call assert_equal('foo', pathshorten('foo')) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 409 | call assert_equal('/foo', '/foo'->pathshorten()) |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 410 | call assert_equal('f/', pathshorten('foo/')) |
| 411 | call assert_equal('f/bar', pathshorten('foo/bar')) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 412 | call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten()) |
Bram Moolenaar | bfde0b4 | 2018-08-08 22:27:31 +0200 | [diff] [blame] | 413 | call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) |
| 414 | call assert_equal('.f/bar', pathshorten('.foo/bar')) |
| 415 | call assert_equal('~f/bar', pathshorten('~foo/bar')) |
| 416 | call assert_equal('~.f/bar', pathshorten('~.foo/bar')) |
| 417 | call assert_equal('.~f/bar', pathshorten('.~foo/bar')) |
| 418 | call assert_equal('~/f/bar', pathshorten('~/foo/bar')) |
| 419 | endfunc |
| 420 | |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 421 | func Test_strpart() |
| 422 | call assert_equal('de', strpart('abcdefg', 3, 2)) |
| 423 | call assert_equal('ab', strpart('abcdefg', -2, 4)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 424 | call assert_equal('abcdefg', 'abcdefg'->strpart(-2)) |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 425 | call assert_equal('fg', strpart('abcdefg', 5, 4)) |
| 426 | call assert_equal('defg', strpart('abcdefg', 3)) |
| 427 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 428 | call assert_equal('lép', strpart('éléphant', 2, 4)) |
| 429 | call assert_equal('léphant', strpart('éléphant', 2)) |
Bram Moolenaar | c7d16dc | 2017-11-18 20:32:03 +0100 | [diff] [blame] | 430 | endfunc |
| 431 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 432 | func Test_tolower() |
| 433 | call assert_equal("", tolower("")) |
| 434 | |
| 435 | " Test with all printable ASCII characters. |
| 436 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', |
| 437 | \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 438 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 439 | " Test with a few uppercase diacritics. |
| 440 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 441 | call assert_equal("bḃḇ", tolower("BḂḆ")) |
| 442 | call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) |
| 443 | call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) |
| 444 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 445 | call assert_equal("fḟ ", tolower("FḞ ")) |
| 446 | call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) |
| 447 | call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) |
| 448 | call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 449 | call assert_equal("jĵ", tolower("JĴ")) |
| 450 | call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) |
| 451 | call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) |
| 452 | call assert_equal("mḿṁ", tolower("MḾṀ")) |
| 453 | call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) |
| 454 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 455 | call assert_equal("pṕṗ", tolower("PṔṖ")) |
| 456 | call assert_equal("q", tolower("Q")) |
| 457 | call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) |
| 458 | call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) |
| 459 | call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) |
| 460 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 461 | call assert_equal("vṽ", tolower("VṼ")) |
| 462 | call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) |
| 463 | call assert_equal("xẋẍ", tolower("XẊẌ")) |
| 464 | call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) |
| 465 | call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) |
| 466 | |
| 467 | " Test with a few lowercase diacritics, which should remain unchanged. |
| 468 | call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) |
| 469 | call assert_equal("bḃḇ", tolower("bḃḇ")) |
| 470 | call assert_equal("cçćĉċč", tolower("cçćĉċč")) |
| 471 | call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) |
| 472 | call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) |
| 473 | call assert_equal("fḟ", tolower("fḟ")) |
| 474 | call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) |
| 475 | call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) |
| 476 | call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) |
| 477 | call assert_equal("jĵǰ", tolower("jĵǰ")) |
| 478 | call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) |
| 479 | call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) |
| 480 | call assert_equal("mḿṁ ", tolower("mḿṁ ")) |
| 481 | call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) |
| 482 | call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) |
| 483 | call assert_equal("pṕṗ", tolower("pṕṗ")) |
| 484 | call assert_equal("q", tolower("q")) |
| 485 | call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) |
| 486 | call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) |
| 487 | call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) |
| 488 | call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) |
| 489 | call assert_equal("vṽ", tolower("vṽ")) |
| 490 | call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) |
| 491 | call assert_equal("ẋẍ", tolower("ẋẍ")) |
| 492 | call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) |
| 493 | call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) |
| 494 | |
| 495 | " According to https://twitter.com/jifa/status/625776454479970304 |
| 496 | " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase |
| 497 | " in length (2 to 3 bytes) when lowercased. So let's test them. |
| 498 | call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) |
Bram Moolenaar | e6640ad | 2017-12-22 21:06:56 +0100 | [diff] [blame] | 499 | |
| 500 | " This call to tolower with invalid utf8 sequence used to cause access to |
| 501 | " invalid memory. |
| 502 | call tolower("\xC0\x80\xC0") |
| 503 | call tolower("123\xC0\x80\xC0") |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 504 | endfunc |
| 505 | |
| 506 | func Test_toupper() |
| 507 | call assert_equal("", toupper("")) |
| 508 | |
| 509 | " Test with all printable ASCII characters. |
| 510 | call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', |
| 511 | \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) |
| 512 | |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 513 | " Test with a few lowercase diacritics. |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 514 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper()) |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 515 | call assert_equal("BḂḆ", toupper("bḃḇ")) |
| 516 | call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) |
| 517 | call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) |
| 518 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) |
| 519 | call assert_equal("FḞ", toupper("fḟ")) |
| 520 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) |
| 521 | call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) |
| 522 | call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) |
| 523 | call assert_equal("JĴǰ", toupper("jĵǰ")) |
| 524 | call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) |
| 525 | call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) |
| 526 | call assert_equal("MḾṀ ", toupper("mḿṁ ")) |
| 527 | call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) |
| 528 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) |
| 529 | call assert_equal("PṔṖ", toupper("pṕṗ")) |
| 530 | call assert_equal("Q", toupper("q")) |
| 531 | call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) |
| 532 | call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) |
| 533 | call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) |
| 534 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) |
| 535 | call assert_equal("VṼ", toupper("vṽ")) |
| 536 | call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) |
| 537 | call assert_equal("ẊẌ", toupper("ẋẍ")) |
| 538 | call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) |
| 539 | call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) |
| 540 | |
| 541 | " Test that uppercase diacritics, which should remain unchanged. |
| 542 | call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) |
| 543 | call assert_equal("BḂḆ", toupper("BḂḆ")) |
| 544 | call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) |
| 545 | call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) |
| 546 | call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) |
| 547 | call assert_equal("FḞ ", toupper("FḞ ")) |
| 548 | call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) |
| 549 | call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) |
| 550 | call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) |
| 551 | call assert_equal("JĴ", toupper("JĴ")) |
| 552 | call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) |
| 553 | call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) |
| 554 | call assert_equal("MḾṀ", toupper("MḾṀ")) |
| 555 | call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) |
| 556 | call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) |
| 557 | call assert_equal("PṔṖ", toupper("PṔṖ")) |
| 558 | call assert_equal("Q", toupper("Q")) |
| 559 | call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) |
| 560 | call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) |
| 561 | call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) |
| 562 | call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) |
| 563 | call assert_equal("VṼ", toupper("VṼ")) |
| 564 | call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) |
| 565 | call assert_equal("XẊẌ", toupper("XẊẌ")) |
| 566 | call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) |
| 567 | call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) |
| 568 | |
Bram Moolenaar | 24c2e48 | 2017-01-29 15:45:12 +0100 | [diff] [blame] | 569 | call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) |
Bram Moolenaar | e6640ad | 2017-12-22 21:06:56 +0100 | [diff] [blame] | 570 | |
| 571 | " This call to toupper with invalid utf8 sequence used to cause access to |
| 572 | " invalid memory. |
| 573 | call toupper("\xC0\x80\xC0") |
| 574 | call toupper("123\xC0\x80\xC0") |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 575 | endfunc |
| 576 | |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 577 | func Test_tr() |
| 578 | call assert_equal('foo', tr('bar', 'bar', 'foo')) |
| 579 | call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) |
| 580 | endfunc |
| 581 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 582 | " Tests for the mode() function |
| 583 | let current_modes = '' |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 584 | func Save_mode() |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 585 | let g:current_modes = mode(0) . '-' . mode(1) |
| 586 | return '' |
| 587 | endfunc |
Bram Moolenaar | cc5b22b | 2017-01-26 22:51:56 +0100 | [diff] [blame] | 588 | |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 589 | func Test_mode() |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 590 | new |
| 591 | call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) |
| 592 | |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 593 | " Only complete from the current buffer. |
| 594 | set complete=. |
| 595 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 596 | inoremap <F2> <C-R>=Save_mode()<CR> |
| 597 | |
| 598 | normal! 3G |
| 599 | exe "normal i\<F2>\<Esc>" |
| 600 | call assert_equal('i-i', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 601 | " i_CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 602 | exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u" |
| 603 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 604 | " i_CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 605 | exe "normal iBro\<C-P>\<F2>\<Esc>u" |
| 606 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 607 | " i_CTRL-X |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 608 | exe "normal iBa\<C-X>\<F2>\<Esc>u" |
| 609 | call assert_equal('i-ix', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 610 | " i_CTRL-X CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 611 | exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 612 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 613 | " i_CTRL-X CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 614 | exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 615 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 616 | " i_CTRL-X CTRL-P + CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 617 | exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 618 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 619 | " i_CTRL-X CTRL-L: Multiple matches |
| 620 | exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u" |
| 621 | call assert_equal('i-ic', g:current_modes) |
| 622 | " i_CTRL-X CTRL-L: Single match |
| 623 | exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u" |
| 624 | call assert_equal('i-ic', g:current_modes) |
| 625 | " i_CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 626 | exe "normal iCom\<C-P>\<F2>\<Esc>u" |
| 627 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 628 | " i_CTRL-X CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 629 | exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 630 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 631 | " i_CTRL-X CTRL-L: No match |
| 632 | exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u" |
| 633 | call assert_equal('i-ic', g:current_modes) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 634 | |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 635 | " R_CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 636 | exe "normal RBa\<C-P>\<F2>\<Esc>u" |
| 637 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 638 | " R_CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 639 | exe "normal RBro\<C-P>\<F2>\<Esc>u" |
| 640 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 641 | " R_CTRL-X |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 642 | exe "normal RBa\<C-X>\<F2>\<Esc>u" |
| 643 | call assert_equal('R-Rx', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 644 | " R_CTRL-X CTRL-P: Multiple matches |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 645 | exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u" |
| 646 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 647 | " R_CTRL-X CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 648 | exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u" |
| 649 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 650 | " R_CTRL-X CTRL-P + CTRL-P: Single match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 651 | exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" |
| 652 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 653 | " R_CTRL-X CTRL-L: Multiple matches |
| 654 | exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u" |
| 655 | call assert_equal('R-Rc', g:current_modes) |
| 656 | " R_CTRL-X CTRL-L: Single match |
| 657 | exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u" |
| 658 | call assert_equal('R-Rc', g:current_modes) |
| 659 | " R_CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 660 | exe "normal RCom\<C-P>\<F2>\<Esc>u" |
| 661 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 662 | " R_CTRL-X CTRL-P: No match |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 663 | exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u" |
| 664 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e971df3 | 2017-02-05 14:15:29 +0100 | [diff] [blame] | 665 | " R_CTRL-X CTRL-L: No match |
| 666 | exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u" |
| 667 | call assert_equal('R-Rc', g:current_modes) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 668 | |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 669 | call assert_equal('n', 0->mode()) |
| 670 | call assert_equal('n', 1->mode()) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 671 | |
Bram Moolenaar | 612cc38 | 2018-07-29 15:34:26 +0200 | [diff] [blame] | 672 | " i_CTRL-O |
| 673 | exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 674 | call assert_equal("n-niI", g:current_modes) |
| 675 | |
| 676 | " R_CTRL-O |
| 677 | exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 678 | call assert_equal("n-niR", g:current_modes) |
| 679 | |
| 680 | " gR_CTRL-O |
| 681 | exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>" |
| 682 | call assert_equal("n-niV", g:current_modes) |
| 683 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 684 | " How to test operator-pending mode? |
| 685 | |
| 686 | call feedkeys("v", 'xt') |
| 687 | call assert_equal('v', mode()) |
| 688 | call assert_equal('v', mode(1)) |
| 689 | call feedkeys("\<Esc>V", 'xt') |
| 690 | call assert_equal('V', mode()) |
| 691 | call assert_equal('V', mode(1)) |
| 692 | call feedkeys("\<Esc>\<C-V>", 'xt') |
| 693 | call assert_equal("\<C-V>", mode()) |
| 694 | call assert_equal("\<C-V>", mode(1)) |
| 695 | call feedkeys("\<Esc>", 'xt') |
| 696 | |
| 697 | call feedkeys("gh", 'xt') |
| 698 | call assert_equal('s', mode()) |
| 699 | call assert_equal('s', mode(1)) |
| 700 | call feedkeys("\<Esc>gH", 'xt') |
| 701 | call assert_equal('S', mode()) |
| 702 | call assert_equal('S', mode(1)) |
| 703 | call feedkeys("\<Esc>g\<C-H>", 'xt') |
| 704 | call assert_equal("\<C-S>", mode()) |
| 705 | call assert_equal("\<C-S>", mode(1)) |
| 706 | call feedkeys("\<Esc>", 'xt') |
| 707 | |
| 708 | call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt') |
| 709 | call assert_equal('c-c', g:current_modes) |
| 710 | call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt') |
| 711 | call assert_equal('c-cv', g:current_modes) |
| 712 | " How to test Ex mode? |
| 713 | |
| 714 | bwipe! |
| 715 | iunmap <F2> |
Bram Moolenaar | ffea8c9 | 2017-03-13 20:37:15 +0100 | [diff] [blame] | 716 | set complete& |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 717 | endfunc |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 718 | |
Bram Moolenaar | d200702 | 2019-08-27 21:56:06 +0200 | [diff] [blame] | 719 | func Test_append() |
| 720 | enew! |
| 721 | split |
| 722 | call append(0, ["foo"]) |
| 723 | split |
| 724 | only |
| 725 | undo |
| 726 | endfunc |
| 727 | |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 728 | func Test_getbufvar() |
| 729 | let bnr = bufnr('%') |
| 730 | let b:var_num = '1234' |
| 731 | let def_num = '5678' |
| 732 | call assert_equal('1234', getbufvar(bnr, 'var_num')) |
| 733 | call assert_equal('1234', getbufvar(bnr, 'var_num', def_num)) |
| 734 | |
| 735 | let bd = getbufvar(bnr, '') |
| 736 | call assert_equal('1234', bd['var_num']) |
| 737 | call assert_true(exists("bd['changedtick']")) |
| 738 | call assert_equal(2, len(bd)) |
| 739 | |
| 740 | let bd2 = getbufvar(bnr, '', def_num) |
| 741 | call assert_equal(bd, bd2) |
| 742 | |
| 743 | unlet b:var_num |
| 744 | call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num)) |
| 745 | call assert_equal('', getbufvar(bnr, 'var_num')) |
| 746 | |
| 747 | let bd = getbufvar(bnr, '') |
| 748 | call assert_equal(1, len(bd)) |
| 749 | let bd = getbufvar(bnr, '',def_num) |
| 750 | call assert_equal(1, len(bd)) |
| 751 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 752 | call assert_equal('', getbufvar(9999, '')) |
| 753 | call assert_equal(def_num, getbufvar(9999, '', def_num)) |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 754 | unlet def_num |
| 755 | |
Bram Moolenaar | 507647d | 2017-02-17 16:43:49 +0100 | [diff] [blame] | 756 | call assert_equal(0, getbufvar(bnr, '&autoindent')) |
| 757 | call assert_equal(0, getbufvar(bnr, '&autoindent', 1)) |
Bram Moolenaar | 79518e2 | 2017-02-17 16:31:35 +0100 | [diff] [blame] | 758 | |
| 759 | " Open new window with forced option values |
| 760 | set fileformats=unix,dos |
| 761 | new ++ff=dos ++bin ++enc=iso-8859-2 |
| 762 | call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat')) |
| 763 | call assert_equal(1, getbufvar(bufnr('%'), '&bin')) |
| 764 | call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc')) |
| 765 | close |
| 766 | |
| 767 | set fileformats& |
| 768 | endfunc |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 769 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 770 | func Test_last_buffer_nr() |
| 771 | call assert_equal(bufnr('$'), last_buffer_nr()) |
| 772 | endfunc |
| 773 | |
| 774 | func Test_stridx() |
| 775 | call assert_equal(-1, stridx('', 'l')) |
| 776 | call assert_equal(0, stridx('', '')) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 777 | call assert_equal(0, 'hello'->stridx('')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 778 | call assert_equal(-1, stridx('hello', 'L')) |
| 779 | call assert_equal(2, stridx('hello', 'l', -1)) |
| 780 | call assert_equal(2, stridx('hello', 'l', 0)) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 781 | call assert_equal(2, 'hello'->stridx('l', 1)) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 782 | call assert_equal(3, stridx('hello', 'l', 3)) |
| 783 | call assert_equal(-1, stridx('hello', 'l', 4)) |
| 784 | call assert_equal(-1, stridx('hello', 'l', 10)) |
| 785 | call assert_equal(2, stridx('hello', 'll')) |
| 786 | call assert_equal(-1, stridx('hello', 'hello world')) |
| 787 | endfunc |
| 788 | |
| 789 | func Test_strridx() |
| 790 | call assert_equal(-1, strridx('', 'l')) |
| 791 | call assert_equal(0, strridx('', '')) |
| 792 | call assert_equal(5, strridx('hello', '')) |
| 793 | call assert_equal(-1, strridx('hello', 'L')) |
Bram Moolenaar | f6ed61e | 2019-09-07 19:05:09 +0200 | [diff] [blame] | 794 | call assert_equal(3, 'hello'->strridx('l')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 795 | call assert_equal(3, strridx('hello', 'l', 10)) |
| 796 | call assert_equal(3, strridx('hello', 'l', 3)) |
| 797 | call assert_equal(2, strridx('hello', 'l', 2)) |
| 798 | call assert_equal(-1, strridx('hello', 'l', 1)) |
| 799 | call assert_equal(-1, strridx('hello', 'l', 0)) |
| 800 | call assert_equal(-1, strridx('hello', 'l', -1)) |
| 801 | call assert_equal(2, strridx('hello', 'll')) |
| 802 | call assert_equal(-1, strridx('hello', 'hello world')) |
| 803 | endfunc |
| 804 | |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 805 | func Test_match_func() |
| 806 | call assert_equal(4, match('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 807 | call assert_equal(4, 'testing'->match('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 808 | call assert_equal(-1, match('testing', 'ing', 5)) |
| 809 | call assert_equal(-1, match('testing', 'ing', 8)) |
| 810 | call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) |
| 811 | call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) |
| 812 | endfunc |
| 813 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 814 | func Test_matchend() |
| 815 | call assert_equal(7, matchend('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 816 | call assert_equal(7, 'testing'->matchend('ing', 2)) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 817 | call assert_equal(-1, matchend('testing', 'ing', 5)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 818 | call assert_equal(-1, matchend('testing', 'ing', 8)) |
| 819 | call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) |
| 820 | call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img')) |
| 821 | endfunc |
| 822 | |
| 823 | func Test_matchlist() |
| 824 | call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 825 | call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 826 | call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) |
| 827 | endfunc |
| 828 | |
| 829 | func Test_matchstr() |
| 830 | call assert_equal('ing', matchstr('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 831 | call assert_equal('ing', 'testing'->matchstr('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 832 | call assert_equal('', matchstr('testing', 'ing', 5)) |
| 833 | call assert_equal('', matchstr('testing', 'ing', 8)) |
| 834 | call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) |
| 835 | call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img')) |
| 836 | endfunc |
| 837 | |
| 838 | func Test_matchstrpos() |
| 839 | call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) |
Bram Moolenaar | a144983 | 2019-09-01 20:16:52 +0200 | [diff] [blame] | 840 | call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2)) |
Bram Moolenaar | 1190cf6 | 2017-09-14 14:31:18 +0200 | [diff] [blame] | 841 | call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) |
| 842 | call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) |
| 843 | call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) |
| 844 | call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 845 | endfunc |
| 846 | |
| 847 | func Test_nextnonblank_prevnonblank() |
| 848 | new |
| 849 | insert |
| 850 | This |
| 851 | |
| 852 | |
| 853 | is |
| 854 | |
| 855 | a |
| 856 | Test |
| 857 | . |
| 858 | call assert_equal(0, nextnonblank(-1)) |
| 859 | call assert_equal(0, nextnonblank(0)) |
| 860 | call assert_equal(1, nextnonblank(1)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 861 | call assert_equal(4, 2->nextnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 862 | call assert_equal(4, nextnonblank(3)) |
| 863 | call assert_equal(4, nextnonblank(4)) |
| 864 | call assert_equal(6, nextnonblank(5)) |
| 865 | call assert_equal(6, nextnonblank(6)) |
| 866 | call assert_equal(7, nextnonblank(7)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 867 | call assert_equal(0, 8->nextnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 868 | |
| 869 | call assert_equal(0, prevnonblank(-1)) |
| 870 | call assert_equal(0, prevnonblank(0)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 871 | call assert_equal(1, 1->prevnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 872 | call assert_equal(1, prevnonblank(2)) |
| 873 | call assert_equal(1, prevnonblank(3)) |
| 874 | call assert_equal(4, prevnonblank(4)) |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 875 | call assert_equal(4, 5->prevnonblank()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 876 | call assert_equal(6, prevnonblank(6)) |
| 877 | call assert_equal(7, prevnonblank(7)) |
| 878 | call assert_equal(0, prevnonblank(8)) |
| 879 | bw! |
| 880 | endfunc |
| 881 | |
| 882 | func Test_byte2line_line2byte() |
| 883 | new |
Bram Moolenaar | c26f7c6 | 2018-08-20 22:53:04 +0200 | [diff] [blame] | 884 | set endofline |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 885 | call setline(1, ['a', 'bc', 'd']) |
| 886 | |
| 887 | set fileformat=unix |
| 888 | call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], |
| 889 | \ map(range(-1, 8), 'byte2line(v:val)')) |
| 890 | call assert_equal([-1, -1, 1, 3, 6, 8, -1], |
| 891 | \ map(range(-1, 5), 'line2byte(v:val)')) |
| 892 | |
| 893 | set fileformat=mac |
| 894 | call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 895 | \ map(range(-1, 8), 'v:val->byte2line()')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 896 | call assert_equal([-1, -1, 1, 3, 6, 8, -1], |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 897 | \ map(range(-1, 5), 'v:val->line2byte()')) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 898 | |
| 899 | set fileformat=dos |
| 900 | call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], |
| 901 | \ map(range(-1, 11), 'byte2line(v:val)')) |
| 902 | call assert_equal([-1, -1, 1, 4, 8, 11, -1], |
| 903 | \ map(range(-1, 5), 'line2byte(v:val)')) |
| 904 | |
Bram Moolenaar | c26f7c6 | 2018-08-20 22:53:04 +0200 | [diff] [blame] | 905 | bw! |
| 906 | set noendofline nofixendofline |
| 907 | normal a- |
| 908 | for ff in ["unix", "mac", "dos"] |
| 909 | let &fileformat = ff |
| 910 | call assert_equal(1, line2byte(1)) |
| 911 | call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). |
| 912 | endfor |
| 913 | |
| 914 | set endofline& fixendofline& fileformat& |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 915 | bw! |
| 916 | endfunc |
| 917 | |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 918 | func Test_byteidx() |
| 919 | let a = '.é.' " one char of two bytes |
| 920 | call assert_equal(0, byteidx(a, 0)) |
| 921 | call assert_equal(0, byteidxcomp(a, 0)) |
| 922 | call assert_equal(1, byteidx(a, 1)) |
| 923 | call assert_equal(1, byteidxcomp(a, 1)) |
| 924 | call assert_equal(3, byteidx(a, 2)) |
| 925 | call assert_equal(3, byteidxcomp(a, 2)) |
| 926 | call assert_equal(4, byteidx(a, 3)) |
| 927 | call assert_equal(4, byteidxcomp(a, 3)) |
| 928 | call assert_equal(-1, byteidx(a, 4)) |
| 929 | call assert_equal(-1, byteidxcomp(a, 4)) |
| 930 | |
| 931 | let b = '.é.' " normal e with composing char |
| 932 | call assert_equal(0, b->byteidx(0)) |
| 933 | call assert_equal(1, b->byteidx(1)) |
| 934 | call assert_equal(4, b->byteidx(2)) |
| 935 | call assert_equal(5, b->byteidx(3)) |
| 936 | call assert_equal(-1, b->byteidx(4)) |
| 937 | |
| 938 | call assert_equal(0, b->byteidxcomp(0)) |
| 939 | call assert_equal(1, b->byteidxcomp(1)) |
| 940 | call assert_equal(2, b->byteidxcomp(2)) |
| 941 | call assert_equal(4, b->byteidxcomp(3)) |
| 942 | call assert_equal(5, b->byteidxcomp(4)) |
| 943 | call assert_equal(-1, b->byteidxcomp(5)) |
| 944 | endfunc |
| 945 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 946 | func Test_count() |
| 947 | let l = ['a', 'a', 'A', 'b'] |
| 948 | call assert_equal(2, count(l, 'a')) |
| 949 | call assert_equal(1, count(l, 'A')) |
| 950 | call assert_equal(1, count(l, 'b')) |
| 951 | call assert_equal(0, count(l, 'B')) |
| 952 | |
| 953 | call assert_equal(2, count(l, 'a', 0)) |
| 954 | call assert_equal(1, count(l, 'A', 0)) |
| 955 | call assert_equal(1, count(l, 'b', 0)) |
| 956 | call assert_equal(0, count(l, 'B', 0)) |
| 957 | |
| 958 | call assert_equal(3, count(l, 'a', 1)) |
| 959 | call assert_equal(3, count(l, 'A', 1)) |
| 960 | call assert_equal(1, count(l, 'b', 1)) |
| 961 | call assert_equal(1, count(l, 'B', 1)) |
| 962 | call assert_equal(0, count(l, 'c', 1)) |
| 963 | |
| 964 | call assert_equal(1, count(l, 'a', 0, 1)) |
| 965 | call assert_equal(2, count(l, 'a', 1, 1)) |
| 966 | call assert_fails('call count(l, "a", 0, 10)', 'E684:') |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 967 | call assert_fails('call count(l, "a", [])', 'E745:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 968 | |
| 969 | let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} |
| 970 | call assert_equal(2, count(d, 'a')) |
| 971 | call assert_equal(1, count(d, 'A')) |
| 972 | call assert_equal(1, count(d, 'b')) |
| 973 | call assert_equal(0, count(d, 'B')) |
| 974 | |
| 975 | call assert_equal(2, count(d, 'a', 0)) |
| 976 | call assert_equal(1, count(d, 'A', 0)) |
| 977 | call assert_equal(1, count(d, 'b', 0)) |
| 978 | call assert_equal(0, count(d, 'B', 0)) |
| 979 | |
| 980 | call assert_equal(3, count(d, 'a', 1)) |
| 981 | call assert_equal(3, count(d, 'A', 1)) |
| 982 | call assert_equal(1, count(d, 'b', 1)) |
| 983 | call assert_equal(1, count(d, 'B', 1)) |
| 984 | call assert_equal(0, count(d, 'c', 1)) |
| 985 | |
| 986 | call assert_fails('call count(d, "a", 0, 1)', 'E474:') |
Bram Moolenaar | 9966b21 | 2017-07-28 16:46:57 +0200 | [diff] [blame] | 987 | |
| 988 | call assert_equal(0, count("foo", "bar")) |
| 989 | call assert_equal(1, count("foo", "oo")) |
| 990 | call assert_equal(2, count("foo", "o")) |
| 991 | call assert_equal(0, count("foo", "O")) |
| 992 | call assert_equal(2, count("foo", "O", 1)) |
| 993 | call assert_equal(2, count("fooooo", "oo")) |
Bram Moolenaar | 338e47f | 2017-12-19 11:55:26 +0100 | [diff] [blame] | 994 | call assert_equal(0, count("foo", "")) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 995 | |
| 996 | call assert_fails('call count(0, 0)', 'E712:') |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 997 | endfunc |
| 998 | |
| 999 | func Test_changenr() |
| 1000 | new Xchangenr |
| 1001 | call assert_equal(0, changenr()) |
| 1002 | norm ifoo |
| 1003 | call assert_equal(1, changenr()) |
| 1004 | set undolevels=10 |
| 1005 | norm Sbar |
| 1006 | call assert_equal(2, changenr()) |
| 1007 | undo |
| 1008 | call assert_equal(1, changenr()) |
| 1009 | redo |
| 1010 | call assert_equal(2, changenr()) |
| 1011 | bw! |
| 1012 | set undolevels& |
| 1013 | endfunc |
| 1014 | |
| 1015 | func Test_filewritable() |
| 1016 | new Xfilewritable |
| 1017 | write! |
| 1018 | call assert_equal(1, filewritable('Xfilewritable')) |
| 1019 | |
| 1020 | call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----')) |
| 1021 | call assert_equal(0, filewritable('Xfilewritable')) |
| 1022 | |
| 1023 | call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1024 | call assert_equal(1, 'Xfilewritable'->filewritable()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1025 | |
| 1026 | call assert_equal(0, filewritable('doesnotexist')) |
| 1027 | |
| 1028 | call delete('Xfilewritable') |
| 1029 | bw! |
| 1030 | endfunc |
| 1031 | |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1032 | func Test_Executable() |
| 1033 | if has('win32') |
| 1034 | call assert_equal(1, executable('notepad')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1035 | call assert_equal(1, 'notepad.exe'->executable()) |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1036 | call assert_equal(0, executable('notepad.exe.exe')) |
| 1037 | call assert_equal(0, executable('shell32.dll')) |
| 1038 | call assert_equal(0, executable('win.ini')) |
| 1039 | elseif has('unix') |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1040 | call assert_equal(1, 'cat'->executable()) |
Bram Moolenaar | a05a0d3 | 2018-10-07 18:43:05 +0200 | [diff] [blame] | 1041 | call assert_equal(0, executable('nodogshere')) |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1042 | |
| 1043 | " get "cat" path and remove the leading / |
| 1044 | let catcmd = exepath('cat')[1:] |
| 1045 | new |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1046 | " check that the relative path works in / |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1047 | lcd / |
| 1048 | call assert_equal(1, executable(catcmd)) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1049 | call assert_equal('/' .. catcmd, catcmd->exepath()) |
Bram Moolenaar | d08b8c4 | 2019-07-24 14:59:45 +0200 | [diff] [blame] | 1050 | bwipe |
Bram Moolenaar | 8295666 | 2018-10-06 15:18:45 +0200 | [diff] [blame] | 1051 | endif |
| 1052 | endfunc |
| 1053 | |
Bram Moolenaar | 8662189 | 2019-03-30 21:51:28 +0100 | [diff] [blame] | 1054 | func Test_executable_longname() |
| 1055 | if !has('win32') |
| 1056 | return |
| 1057 | endif |
| 1058 | |
| 1059 | let fname = 'X' . repeat('あ', 200) . '.bat' |
| 1060 | call writefile([], fname) |
| 1061 | call assert_equal(1, executable(fname)) |
| 1062 | call delete(fname) |
| 1063 | endfunc |
| 1064 | |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1065 | func Test_hostname() |
| 1066 | let hostname_vim = hostname() |
| 1067 | if has('unix') |
| 1068 | let hostname_system = systemlist('uname -n')[0] |
| 1069 | call assert_equal(hostname_vim, hostname_system) |
| 1070 | endif |
| 1071 | endfunc |
| 1072 | |
| 1073 | func Test_getpid() |
| 1074 | " getpid() always returns the same value within a vim instance. |
| 1075 | call assert_equal(getpid(), getpid()) |
| 1076 | if has('unix') |
| 1077 | call assert_equal(systemlist('echo $PPID')[0], string(getpid())) |
| 1078 | endif |
| 1079 | endfunc |
| 1080 | |
| 1081 | func Test_hlexists() |
| 1082 | call assert_equal(0, hlexists('does_not_exist')) |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1083 | call assert_equal(0, 'Number'->hlexists()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1084 | call assert_equal(0, highlight_exists('does_not_exist')) |
| 1085 | call assert_equal(0, highlight_exists('Number')) |
| 1086 | syntax on |
| 1087 | call assert_equal(0, hlexists('does_not_exist')) |
| 1088 | call assert_equal(1, hlexists('Number')) |
| 1089 | call assert_equal(0, highlight_exists('does_not_exist')) |
| 1090 | call assert_equal(1, highlight_exists('Number')) |
| 1091 | syntax off |
| 1092 | endfunc |
| 1093 | |
| 1094 | func Test_col() |
| 1095 | new |
| 1096 | call setline(1, 'abcdef') |
| 1097 | norm gg4|mx6|mY2| |
| 1098 | call assert_equal(2, col('.')) |
| 1099 | call assert_equal(7, col('$')) |
| 1100 | call assert_equal(4, col("'x")) |
| 1101 | call assert_equal(6, col("'Y")) |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1102 | call assert_equal(2, [1, 2]->col()) |
Bram Moolenaar | 41042f3 | 2017-03-09 12:09:32 +0100 | [diff] [blame] | 1103 | call assert_equal(7, col([1, '$'])) |
| 1104 | |
| 1105 | call assert_equal(0, col('')) |
| 1106 | call assert_equal(0, col('x')) |
| 1107 | call assert_equal(0, col([2, '$'])) |
| 1108 | call assert_equal(0, col([1, 100])) |
| 1109 | call assert_equal(0, col([1])) |
| 1110 | bw! |
| 1111 | endfunc |
| 1112 | |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1113 | func Test_inputlist() |
| 1114 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') |
| 1115 | call assert_equal(1, c) |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1116 | call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx') |
Bram Moolenaar | 947b39e | 2018-07-22 19:36:37 +0200 | [diff] [blame] | 1117 | call assert_equal(2, c) |
| 1118 | call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') |
| 1119 | call assert_equal(3, c) |
| 1120 | |
| 1121 | call assert_fails('call inputlist("")', 'E686:') |
| 1122 | endfunc |
| 1123 | |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 1124 | func Test_balloon_show() |
Bram Moolenaar | a0107bd | 2017-03-02 22:48:01 +0100 | [diff] [blame] | 1125 | if has('balloon_eval') |
| 1126 | " This won't do anything but must not crash either. |
| 1127 | call balloon_show('hi!') |
| 1128 | endif |
Bram Moolenaar | caf6434 | 2017-03-02 22:11:33 +0100 | [diff] [blame] | 1129 | endfunc |
Bram Moolenaar | 2c90d51 | 2017-03-18 22:35:30 +0100 | [diff] [blame] | 1130 | |
| 1131 | func Test_setbufvar_options() |
| 1132 | " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the |
| 1133 | " window layout. |
| 1134 | call assert_equal(1, winnr('$')) |
| 1135 | split dummy_preview |
| 1136 | resize 2 |
| 1137 | set winfixheight winfixwidth |
| 1138 | let prev_id = win_getid() |
| 1139 | |
| 1140 | wincmd j |
| 1141 | let wh = winheight('.') |
| 1142 | let dummy_buf = bufnr('dummy_buf1', v:true) |
| 1143 | call setbufvar(dummy_buf, '&buftype', 'nofile') |
| 1144 | execute 'belowright vertical split #' . dummy_buf |
| 1145 | call assert_equal(wh, winheight('.')) |
| 1146 | let dum1_id = win_getid() |
| 1147 | |
| 1148 | wincmd h |
| 1149 | let wh = winheight('.') |
| 1150 | let dummy_buf = bufnr('dummy_buf2', v:true) |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1151 | eval 'nofile'->setbufvar(dummy_buf, '&buftype') |
Bram Moolenaar | 2c90d51 | 2017-03-18 22:35:30 +0100 | [diff] [blame] | 1152 | execute 'belowright vertical split #' . dummy_buf |
| 1153 | call assert_equal(wh, winheight('.')) |
| 1154 | |
| 1155 | bwipe! |
| 1156 | call win_gotoid(prev_id) |
| 1157 | bwipe! |
| 1158 | call win_gotoid(dum1_id) |
| 1159 | bwipe! |
| 1160 | endfunc |
Bram Moolenaar | d4863aa | 2017-04-07 19:50:12 +0200 | [diff] [blame] | 1161 | |
| 1162 | func Test_redo_in_nested_functions() |
| 1163 | nnoremap g. :set opfunc=Operator<CR>g@ |
| 1164 | function Operator( type, ... ) |
| 1165 | let @x = 'XXX' |
| 1166 | execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp' |
| 1167 | endfunction |
| 1168 | |
| 1169 | function! Apply() |
| 1170 | 5,6normal! . |
| 1171 | endfunction |
| 1172 | |
| 1173 | new |
| 1174 | call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3)) |
| 1175 | 1normal g.i" |
| 1176 | call assert_equal('some "XXX" text', getline(1)) |
| 1177 | 3,4normal . |
| 1178 | call assert_equal('some "XXX" text', getline(3)) |
| 1179 | call assert_equal('more "XXX" text', getline(4)) |
| 1180 | call Apply() |
| 1181 | call assert_equal('some "XXX" text', getline(5)) |
| 1182 | call assert_equal('more "XXX" text', getline(6)) |
| 1183 | bwipe! |
| 1184 | |
| 1185 | nunmap g. |
| 1186 | delfunc Operator |
| 1187 | delfunc Apply |
| 1188 | endfunc |
Bram Moolenaar | 2061552 | 2017-06-05 18:46:26 +0200 | [diff] [blame] | 1189 | |
| 1190 | func Test_shellescape() |
| 1191 | let save_shell = &shell |
| 1192 | set shell=bash |
| 1193 | call assert_equal("'text'", shellescape('text')) |
Bram Moolenaar | aad222c | 2019-09-06 22:46:09 +0200 | [diff] [blame] | 1194 | call assert_equal("'te\"xt'", 'te"xt'->shellescape()) |
Bram Moolenaar | 2061552 | 2017-06-05 18:46:26 +0200 | [diff] [blame] | 1195 | call assert_equal("'te'\\''xt'", shellescape("te'xt")) |
| 1196 | |
| 1197 | call assert_equal("'te%xt'", shellescape("te%xt")) |
| 1198 | call assert_equal("'te\\%xt'", shellescape("te%xt", 1)) |
| 1199 | call assert_equal("'te#xt'", shellescape("te#xt")) |
| 1200 | call assert_equal("'te\\#xt'", shellescape("te#xt", 1)) |
| 1201 | call assert_equal("'te!xt'", shellescape("te!xt")) |
| 1202 | call assert_equal("'te\\!xt'", shellescape("te!xt", 1)) |
| 1203 | |
| 1204 | call assert_equal("'te\nxt'", shellescape("te\nxt")) |
| 1205 | call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1)) |
| 1206 | set shell=tcsh |
| 1207 | call assert_equal("'te\\!xt'", shellescape("te!xt")) |
| 1208 | call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1)) |
| 1209 | call assert_equal("'te\\\nxt'", shellescape("te\nxt")) |
| 1210 | call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1)) |
| 1211 | |
| 1212 | let &shell = save_shell |
| 1213 | endfunc |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1214 | |
| 1215 | func Test_trim() |
| 1216 | call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 1217 | call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim()) |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1218 | call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) |
| 1219 | call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) |
| 1220 | call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) |
| 1221 | call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " ")) |
| 1222 | call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) |
| 1223 | call assert_equal("RESERVE", trim("你RESERVE好", "你好")) |
| 1224 | call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) |
| 1225 | call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) |
| 1226 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) |
| 1227 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) |
| 1228 | call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) |
| 1229 | call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要")) |
| 1230 | call assert_equal("", trim("", "")) |
| 1231 | call assert_equal("a", trim("a", "")) |
| 1232 | call assert_equal("", trim("", "a")) |
| 1233 | |
Bram Moolenaar | 3f4f3d8 | 2019-09-04 20:05:59 +0200 | [diff] [blame] | 1234 | let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '') |
Bram Moolenaar | 295ac5a | 2018-03-22 23:04:02 +0100 | [diff] [blame] | 1235 | call assert_equal("x", trim(chars . "x" . chars)) |
| 1236 | endfunc |
Bram Moolenaar | 0b6d911 | 2018-05-22 20:35:17 +0200 | [diff] [blame] | 1237 | |
| 1238 | " Test for reg_recording() and reg_executing() |
| 1239 | func Test_reg_executing_and_recording() |
| 1240 | let s:reg_stat = '' |
| 1241 | func s:save_reg_stat() |
| 1242 | let s:reg_stat = reg_recording() . ':' . reg_executing() |
| 1243 | return '' |
| 1244 | endfunc |
| 1245 | |
| 1246 | new |
| 1247 | call s:save_reg_stat() |
| 1248 | call assert_equal(':', s:reg_stat) |
| 1249 | call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt') |
| 1250 | call assert_equal('a:', s:reg_stat) |
| 1251 | call feedkeys("@a", 'xt') |
| 1252 | call assert_equal(':a', s:reg_stat) |
| 1253 | call feedkeys("qb@aq", 'xt') |
| 1254 | call assert_equal('b:a', s:reg_stat) |
| 1255 | call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt') |
| 1256 | call assert_equal('":', s:reg_stat) |
| 1257 | |
Bram Moolenaar | cce713d | 2019-03-04 11:40:12 +0100 | [diff] [blame] | 1258 | " :normal command saves and restores reg_executing |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1259 | let s:reg_stat = '' |
Bram Moolenaar | cce713d | 2019-03-04 11:40:12 +0100 | [diff] [blame] | 1260 | let @q = ":call TestFunc()\<CR>:call s:save_reg_stat()\<CR>" |
| 1261 | func TestFunc() abort |
| 1262 | normal! ia |
| 1263 | endfunc |
| 1264 | call feedkeys("@q", 'xt') |
| 1265 | call assert_equal(':q', s:reg_stat) |
| 1266 | delfunc TestFunc |
| 1267 | |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1268 | " getchar() command saves and restores reg_executing |
| 1269 | map W :call TestFunc()<CR> |
| 1270 | let @q = "W" |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1271 | let g:typed = '' |
| 1272 | let g:regs = [] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1273 | func TestFunc() abort |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1274 | let g:regs += [reg_executing()] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1275 | let g:typed = getchar(0) |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1276 | let g:regs += [reg_executing()] |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1277 | endfunc |
| 1278 | call feedkeys("@qy", 'xt') |
| 1279 | call assert_equal(char2nr("y"), g:typed) |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1280 | call assert_equal(['q', 'q'], g:regs) |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1281 | delfunc TestFunc |
| 1282 | unmap W |
| 1283 | unlet g:typed |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1284 | unlet g:regs |
| 1285 | |
| 1286 | " input() command saves and restores reg_executing |
| 1287 | map W :call TestFunc()<CR> |
| 1288 | let @q = "W" |
| 1289 | let g:typed = '' |
| 1290 | let g:regs = [] |
| 1291 | func TestFunc() abort |
| 1292 | let g:regs += [reg_executing()] |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1293 | let g:typed = '?'->input() |
Bram Moolenaar | 9a2c091 | 2019-03-30 14:26:18 +0100 | [diff] [blame] | 1294 | let g:regs += [reg_executing()] |
| 1295 | endfunc |
| 1296 | call feedkeys("@qy\<CR>", 'xt') |
| 1297 | call assert_equal("y", g:typed) |
| 1298 | call assert_equal(['q', 'q'], g:regs) |
| 1299 | delfunc TestFunc |
| 1300 | unmap W |
| 1301 | unlet g:typed |
| 1302 | unlet g:regs |
Bram Moolenaar | f0fab30 | 2019-03-05 12:24:10 +0100 | [diff] [blame] | 1303 | |
Bram Moolenaar | 0b6d911 | 2018-05-22 20:35:17 +0200 | [diff] [blame] | 1304 | bwipe! |
| 1305 | delfunc s:save_reg_stat |
| 1306 | unlet s:reg_stat |
| 1307 | endfunc |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1308 | |
Bram Moolenaar | f9f24ce | 2019-08-31 21:17:39 +0200 | [diff] [blame] | 1309 | func Test_inputsecret() |
| 1310 | map W :call TestFunc()<CR> |
| 1311 | let @q = "W" |
| 1312 | let g:typed1 = '' |
| 1313 | let g:typed2 = '' |
| 1314 | let g:regs = [] |
| 1315 | func TestFunc() abort |
| 1316 | let g:typed1 = '?'->inputsecret() |
| 1317 | let g:typed2 = inputsecret('password: ') |
| 1318 | endfunc |
| 1319 | call feedkeys("@qsomething\<CR>else\<CR>", 'xt') |
| 1320 | call assert_equal("something", g:typed1) |
| 1321 | call assert_equal("else", g:typed2) |
| 1322 | delfunc TestFunc |
| 1323 | unmap W |
| 1324 | unlet g:typed1 |
| 1325 | unlet g:typed2 |
| 1326 | endfunc |
| 1327 | |
Bram Moolenaar | 5d712e4 | 2019-09-03 23:37:01 +0200 | [diff] [blame] | 1328 | func Test_getchar() |
| 1329 | call feedkeys('a', '') |
| 1330 | call assert_equal(char2nr('a'), getchar()) |
| 1331 | |
| 1332 | call test_setmouse(1, 3) |
| 1333 | let v:mouse_win = 9 |
| 1334 | let v:mouse_winid = 9 |
| 1335 | let v:mouse_lnum = 9 |
| 1336 | let v:mouse_col = 9 |
| 1337 | call feedkeys("\<S-LeftMouse>", '') |
| 1338 | call assert_equal("\<S-LeftMouse>", getchar()) |
| 1339 | call assert_equal(1, v:mouse_win) |
| 1340 | call assert_equal(win_getid(1), v:mouse_winid) |
| 1341 | call assert_equal(1, v:mouse_lnum) |
| 1342 | call assert_equal(3, v:mouse_col) |
| 1343 | endfunc |
| 1344 | |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1345 | func Test_libcall_libcallnr() |
| 1346 | if !has('libcall') |
| 1347 | return |
| 1348 | endif |
| 1349 | |
| 1350 | if has('win32') |
| 1351 | let libc = 'msvcrt.dll' |
| 1352 | elseif has('mac') |
| 1353 | let libc = 'libSystem.B.dylib' |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1354 | elseif executable('ldd') |
| 1355 | let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>') |
| 1356 | endif |
| 1357 | if get(l:, 'libc', '') ==# '' |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1358 | " On Unix, libc.so can be in various places. |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1359 | if has('linux') |
| 1360 | " There is not documented but regarding the 1st argument of glibc's |
| 1361 | " dlopen an empty string and nullptr are equivalent, so using an empty |
| 1362 | " string for the 1st argument of libcall allows to call functions. |
| 1363 | let libc = '' |
| 1364 | elseif has('sun') |
| 1365 | " Set the path to libc.so according to the architecture. |
| 1366 | let test_bits = system('file ' . GetVimProg()) |
| 1367 | let test_arch = system('uname -p') |
| 1368 | if test_bits =~ '64-bit' && test_arch =~ 'sparc' |
| 1369 | let libc = '/usr/lib/sparcv9/libc.so' |
| 1370 | elseif test_bits =~ '64-bit' && test_arch =~ 'i386' |
| 1371 | let libc = '/usr/lib/amd64/libc.so' |
| 1372 | else |
| 1373 | let libc = '/usr/lib/libc.so' |
| 1374 | endif |
| 1375 | else |
| 1376 | " Unfortunately skip this test until a good way is found. |
| 1377 | return |
| 1378 | endif |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1379 | endif |
| 1380 | |
| 1381 | if has('win32') |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1382 | call assert_equal($USERPROFILE, 'USERPROFILE'->libcall(libc, 'getenv')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1383 | else |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1384 | call assert_equal($HOME, 'HOME'->libcall(libc, 'getenv')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1385 | endif |
| 1386 | |
| 1387 | " If function returns NULL, libcall() should return an empty string. |
| 1388 | call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) |
| 1389 | |
| 1390 | " Test libcallnr() with string and integer argument. |
Bram Moolenaar | 02b3111 | 2019-08-31 22:16:38 +0200 | [diff] [blame] | 1391 | call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen')) |
| 1392 | call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper')) |
Bram Moolenaar | 1ceebb4 | 2018-06-19 19:46:06 +0200 | [diff] [blame] | 1393 | |
| 1394 | call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') |
| 1395 | call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') |
| 1396 | |
| 1397 | call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:') |
| 1398 | call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:') |
| 1399 | endfunc |
Bram Moolenaar | d90a144 | 2018-07-15 20:24:31 +0200 | [diff] [blame] | 1400 | |
| 1401 | sandbox function Fsandbox() |
| 1402 | normal ix |
| 1403 | endfunc |
| 1404 | |
| 1405 | func Test_func_sandbox() |
| 1406 | sandbox let F = {-> 'hello'} |
| 1407 | call assert_equal('hello', F()) |
| 1408 | |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1409 | sandbox let F = {-> "normal ix\<Esc>"->execute()} |
Bram Moolenaar | d90a144 | 2018-07-15 20:24:31 +0200 | [diff] [blame] | 1410 | call assert_fails('call F()', 'E48:') |
| 1411 | unlet F |
| 1412 | |
| 1413 | call assert_fails('call Fsandbox()', 'E48:') |
| 1414 | delfunc Fsandbox |
| 1415 | endfunc |
Bram Moolenaar | 9e353b5 | 2018-11-04 23:39:38 +0100 | [diff] [blame] | 1416 | |
| 1417 | func EditAnotherFile() |
| 1418 | let word = expand('<cword>') |
| 1419 | edit Xfuncrange2 |
| 1420 | endfunc |
| 1421 | |
| 1422 | func Test_func_range_with_edit() |
| 1423 | " Define a function that edits another buffer, then call it with a range that |
| 1424 | " is invalid in that buffer. |
| 1425 | call writefile(['just one line'], 'Xfuncrange2') |
| 1426 | new |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1427 | eval 10->range()->setline(1) |
Bram Moolenaar | 9e353b5 | 2018-11-04 23:39:38 +0100 | [diff] [blame] | 1428 | write Xfuncrange1 |
| 1429 | call assert_fails('5,8call EditAnotherFile()', 'E16:') |
| 1430 | |
| 1431 | call delete('Xfuncrange1') |
| 1432 | call delete('Xfuncrange2') |
| 1433 | bwipe! |
| 1434 | endfunc |
Bram Moolenaar | ded5f1b | 2018-11-10 17:33:29 +0100 | [diff] [blame] | 1435 | |
| 1436 | func Test_func_exists_on_reload() |
| 1437 | call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') |
| 1438 | call assert_equal(0, exists('*ExistingFunction')) |
| 1439 | source Xfuncexists |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1440 | call assert_equal(1, '*ExistingFunction'->exists()) |
Bram Moolenaar | ded5f1b | 2018-11-10 17:33:29 +0100 | [diff] [blame] | 1441 | " Redefining a function when reloading a script is OK. |
| 1442 | source Xfuncexists |
| 1443 | call assert_equal(1, exists('*ExistingFunction')) |
| 1444 | |
| 1445 | " But redefining in another script is not OK. |
| 1446 | call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2') |
| 1447 | call assert_fails('source Xfuncexists2', 'E122:') |
| 1448 | |
| 1449 | delfunc ExistingFunction |
| 1450 | call assert_equal(0, exists('*ExistingFunction')) |
| 1451 | call writefile([ |
| 1452 | \ 'func ExistingFunction()', 'echo "yes"', 'endfunc', |
| 1453 | \ 'func ExistingFunction()', 'echo "no"', 'endfunc', |
| 1454 | \ ], 'Xfuncexists') |
| 1455 | call assert_fails('source Xfuncexists', 'E122:') |
| 1456 | call assert_equal(1, exists('*ExistingFunction')) |
| 1457 | |
| 1458 | call delete('Xfuncexists2') |
| 1459 | call delete('Xfuncexists') |
| 1460 | delfunc ExistingFunction |
| 1461 | endfunc |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1462 | |
| 1463 | " Test confirm({msg} [, {choices} [, {default} [, {type}]]]) |
| 1464 | func Test_confirm() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1465 | CheckUnix |
| 1466 | CheckNotGui |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1467 | |
| 1468 | call feedkeys('o', 'L') |
| 1469 | let a = confirm('Press O to proceed') |
| 1470 | call assert_equal(1, a) |
| 1471 | |
| 1472 | call feedkeys('y', 'L') |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1473 | let a = 'Are you sure?'->confirm("&Yes\n&No") |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1474 | call assert_equal(1, a) |
| 1475 | |
| 1476 | call feedkeys('n', 'L') |
| 1477 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1478 | call assert_equal(2, a) |
| 1479 | |
| 1480 | " confirm() should return 0 when pressing CTRL-C. |
| 1481 | call feedkeys("\<C-c>", 'L') |
| 1482 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1483 | call assert_equal(0, a) |
| 1484 | |
| 1485 | " <Esc> requires another character to avoid it being seen as the start of an |
| 1486 | " escape sequence. Zero should be harmless. |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1487 | eval "\<Esc>0"->feedkeys('L') |
Bram Moolenaar | 2e05009 | 2019-01-27 15:00:36 +0100 | [diff] [blame] | 1488 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1489 | call assert_equal(0, a) |
| 1490 | |
| 1491 | " Default choice is returned when pressing <CR>. |
| 1492 | call feedkeys("\<CR>", 'L') |
| 1493 | let a = confirm('Are you sure?', "&Yes\n&No") |
| 1494 | call assert_equal(1, a) |
| 1495 | |
| 1496 | call feedkeys("\<CR>", 'L') |
| 1497 | let a = confirm('Are you sure?', "&Yes\n&No", 2) |
| 1498 | call assert_equal(2, a) |
| 1499 | |
| 1500 | call feedkeys("\<CR>", 'L') |
| 1501 | let a = confirm('Are you sure?', "&Yes\n&No", 0) |
| 1502 | call assert_equal(0, a) |
| 1503 | |
| 1504 | " Test with the {type} 4th argument |
| 1505 | for type in ['Error', 'Question', 'Info', 'Warning', 'Generic'] |
| 1506 | call feedkeys('y', 'L') |
| 1507 | let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type) |
| 1508 | call assert_equal(1, a) |
| 1509 | endfor |
| 1510 | |
| 1511 | call assert_fails('call confirm([])', 'E730:') |
| 1512 | call assert_fails('call confirm("Are you sure?", [])', 'E730:') |
| 1513 | call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:') |
| 1514 | call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:') |
| 1515 | endfunc |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1516 | |
| 1517 | func Test_platform_name() |
| 1518 | " The system matches at most only one name. |
| 1519 | let names = ['amiga', 'beos', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix'] |
| 1520 | call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)'))) |
| 1521 | |
| 1522 | " Is Unix? |
| 1523 | call assert_equal(has('beos'), has('beos') && has('unix')) |
| 1524 | call assert_equal(has('bsd'), has('bsd') && has('unix')) |
| 1525 | call assert_equal(has('hpux'), has('hpux') && has('unix')) |
| 1526 | call assert_equal(has('linux'), has('linux') && has('unix')) |
| 1527 | call assert_equal(has('mac'), has('mac') && has('unix')) |
| 1528 | call assert_equal(has('qnx'), has('qnx') && has('unix')) |
| 1529 | call assert_equal(has('sun'), has('sun') && has('unix')) |
| 1530 | call assert_equal(has('win32'), has('win32') && !has('unix')) |
| 1531 | call assert_equal(has('win32unix'), has('win32unix') && has('unix')) |
| 1532 | |
| 1533 | if has('unix') && executable('uname') |
| 1534 | let uname = system('uname') |
| 1535 | call assert_equal(uname =~? 'BeOS', has('beos')) |
Bram Moolenaar | a02e3f6 | 2019-02-07 21:27:14 +0100 | [diff] [blame] | 1536 | " GNU userland on BSD kernels (e.g., GNU/kFreeBSD) don't have BSD defined |
| 1537 | call assert_equal(uname =~? '\%(GNU/k\w\+\)\@<!BSD\|DragonFly', has('bsd')) |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 1538 | call assert_equal(uname =~? 'HP-UX', has('hpux')) |
| 1539 | call assert_equal(uname =~? 'Linux', has('linux')) |
| 1540 | call assert_equal(uname =~? 'Darwin', has('mac')) |
| 1541 | call assert_equal(uname =~? 'QNX', has('qnx')) |
| 1542 | call assert_equal(uname =~? 'SunOS', has('sun')) |
| 1543 | call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) |
| 1544 | endif |
| 1545 | endfunc |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1546 | |
| 1547 | func Test_readdir() |
| 1548 | call mkdir('Xdir') |
| 1549 | call writefile([], 'Xdir/foo.txt') |
| 1550 | call writefile([], 'Xdir/bar.txt') |
| 1551 | call mkdir('Xdir/dir') |
| 1552 | |
| 1553 | " All results |
| 1554 | let files = readdir('Xdir') |
| 1555 | call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) |
| 1556 | |
| 1557 | " Only results containing "f" |
Bram Moolenaar | a0d1fef | 2019-09-04 22:29:14 +0200 | [diff] [blame] | 1558 | let files = 'Xdir'->readdir({ x -> stridx(x, 'f') !=- 1 }) |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1559 | call assert_equal(['foo.txt'], sort(files)) |
| 1560 | |
| 1561 | " Only .txt files |
| 1562 | let files = readdir('Xdir', { x -> x =~ '.txt$' }) |
| 1563 | call assert_equal(['bar.txt', 'foo.txt'], sort(files)) |
| 1564 | |
| 1565 | " Only .txt files with string |
| 1566 | let files = readdir('Xdir', 'v:val =~ ".txt$"') |
| 1567 | call assert_equal(['bar.txt', 'foo.txt'], sort(files)) |
| 1568 | |
| 1569 | " Limit to 1 result. |
| 1570 | let l = [] |
| 1571 | let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) |
| 1572 | call assert_equal(1, len(files)) |
| 1573 | |
Bram Moolenaar | 27da7de | 2019-09-03 17:13:37 +0200 | [diff] [blame] | 1574 | " Nested readdir() must not crash |
| 1575 | let files = readdir('Xdir', 'readdir("Xdir", "1") != []') |
| 1576 | call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt']) |
| 1577 | |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1578 | eval 'Xdir'->delete('rf') |
Bram Moolenaar | 543c9b1 | 2019-04-05 22:50:40 +0200 | [diff] [blame] | 1579 | endfunc |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1580 | |
Bram Moolenaar | 701ff0a | 2019-05-24 14:14:14 +0200 | [diff] [blame] | 1581 | func Test_delete_rf() |
| 1582 | call mkdir('Xdir') |
| 1583 | call writefile([], 'Xdir/foo.txt') |
| 1584 | call writefile([], 'Xdir/bar.txt') |
| 1585 | call mkdir('Xdir/[a-1]') " issue #696 |
| 1586 | call writefile([], 'Xdir/[a-1]/foo.txt') |
| 1587 | call writefile([], 'Xdir/[a-1]/bar.txt') |
| 1588 | call assert_true(filereadable('Xdir/foo.txt')) |
Bram Moolenaar | a420896 | 2019-08-24 20:50:19 +0200 | [diff] [blame] | 1589 | call assert_true('Xdir/[a-1]/foo.txt'->filereadable()) |
Bram Moolenaar | 701ff0a | 2019-05-24 14:14:14 +0200 | [diff] [blame] | 1590 | |
| 1591 | call assert_equal(0, delete('Xdir', 'rf')) |
| 1592 | call assert_false(filereadable('Xdir/foo.txt')) |
| 1593 | call assert_false(filereadable('Xdir/[a-1]/foo.txt')) |
| 1594 | endfunc |
| 1595 | |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1596 | func Test_call() |
| 1597 | call assert_equal(3, call('len', [123])) |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1598 | call assert_equal(3, 'len'->call([123])) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1599 | call assert_fails("call call('len', 123)", 'E714:') |
| 1600 | call assert_equal(0, call('', [])) |
| 1601 | |
| 1602 | function Mylen() dict |
| 1603 | return len(self.data) |
| 1604 | endfunction |
| 1605 | let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} |
Bram Moolenaar | 64b4d73 | 2019-08-22 22:18:17 +0200 | [diff] [blame] | 1606 | eval mydict.len->call([], mydict)->assert_equal(4) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1607 | call assert_fails("call call('Mylen', [], 0)", 'E715:') |
| 1608 | endfunc |
| 1609 | |
| 1610 | func Test_char2nr() |
| 1611 | call assert_equal(12354, char2nr('あ', 1)) |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1612 | call assert_equal(120, 'x'->char2nr()) |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 1613 | endfunc |
| 1614 | |
| 1615 | func Test_eventhandler() |
| 1616 | call assert_equal(0, eventhandler()) |
| 1617 | endfunc |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1618 | |
| 1619 | func Test_bufadd_bufload() |
| 1620 | call assert_equal(0, bufexists('someName')) |
| 1621 | let buf = bufadd('someName') |
| 1622 | call assert_notequal(0, buf) |
| 1623 | call assert_equal(1, bufexists('someName')) |
| 1624 | call assert_equal(0, getbufvar(buf, '&buflisted')) |
| 1625 | call assert_equal(0, bufloaded(buf)) |
| 1626 | call bufload(buf) |
| 1627 | call assert_equal(1, bufloaded(buf)) |
| 1628 | call assert_equal([''], getbufline(buf, 1, '$')) |
| 1629 | |
| 1630 | let curbuf = bufnr('') |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 1631 | eval ['some', 'text']->writefile('XotherName') |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1632 | let buf = 'XotherName'->bufadd() |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1633 | call assert_notequal(0, buf) |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1634 | eval 'XotherName'->bufexists()->assert_equal(1) |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1635 | call assert_equal(0, getbufvar(buf, '&buflisted')) |
| 1636 | call assert_equal(0, bufloaded(buf)) |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 1637 | eval buf->bufload() |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1638 | call assert_equal(1, bufloaded(buf)) |
| 1639 | call assert_equal(['some', 'text'], getbufline(buf, 1, '$')) |
| 1640 | call assert_equal(curbuf, bufnr('')) |
| 1641 | |
Bram Moolenaar | 892ae72 | 2019-06-30 20:33:01 +0200 | [diff] [blame] | 1642 | let buf1 = bufadd('') |
| 1643 | let buf2 = bufadd('') |
| 1644 | call assert_notequal(0, buf1) |
| 1645 | call assert_notequal(0, buf2) |
| 1646 | call assert_notequal(buf1, buf2) |
| 1647 | call assert_equal(1, bufexists(buf1)) |
| 1648 | call assert_equal(1, bufexists(buf2)) |
| 1649 | call assert_equal(0, bufloaded(buf1)) |
| 1650 | exe 'bwipe ' .. buf1 |
| 1651 | call assert_equal(0, bufexists(buf1)) |
| 1652 | call assert_equal(1, bufexists(buf2)) |
| 1653 | exe 'bwipe ' .. buf2 |
| 1654 | call assert_equal(0, bufexists(buf2)) |
| 1655 | |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1656 | bwipe someName |
Bram Moolenaar | 3940ec6 | 2019-07-05 21:53:24 +0200 | [diff] [blame] | 1657 | bwipe XotherName |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1658 | call assert_equal(0, bufexists('someName')) |
Bram Moolenaar | 3940ec6 | 2019-07-05 21:53:24 +0200 | [diff] [blame] | 1659 | call delete('XotherName') |
Bram Moolenaar | 15e248e | 2019-06-30 20:21:37 +0200 | [diff] [blame] | 1660 | endfunc |