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