blob: d53499950e8ef42e2824aca8142f90a950d8dab9 [file] [log] [blame]
Bram Moolenaar08243d22017-01-10 16:12:29 +01001" Tests for various functions.
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02002source shared.vim
Bram Moolenaar08243d22017-01-10 16:12:29 +01003
Bram Moolenaarc7d16dc2017-11-18 20:32:03 +01004" Must be done first, since the alternate buffer must be unset.
5func Test_00_bufexists()
6 call assert_equal(0, bufexists('does_not_exist'))
7 call assert_equal(1, bufexists(bufnr('%')))
8 call assert_equal(0, bufexists(0))
9 new Xfoo
10 let bn = bufnr('%')
11 call assert_equal(1, bufexists(bn))
12 call assert_equal(1, bufexists('Xfoo'))
13 call assert_equal(1, bufexists(getcwd() . '/Xfoo'))
14 call assert_equal(1, bufexists(0))
15 bw
16 call assert_equal(0, bufexists(bn))
17 call assert_equal(0, bufexists('Xfoo'))
18endfunc
19
Bram Moolenaar24c2e482017-01-29 15:45:12 +010020func Test_empty()
21 call assert_equal(1, empty(''))
22 call assert_equal(0, empty('a'))
23
24 call assert_equal(1, empty(0))
25 call assert_equal(1, empty(-0))
26 call assert_equal(0, empty(1))
27 call assert_equal(0, empty(-1))
28
29 call assert_equal(1, empty(0.0))
30 call assert_equal(1, empty(-0.0))
31 call assert_equal(0, empty(1.0))
32 call assert_equal(0, empty(-1.0))
33 call assert_equal(0, empty(1.0/0.0))
34 call assert_equal(0, empty(0.0/0.0))
35
36 call assert_equal(1, empty([]))
37 call assert_equal(0, empty(['a']))
38
39 call assert_equal(1, empty({}))
40 call assert_equal(0, empty({'a':1}))
41
42 call assert_equal(1, empty(v:null))
43 call assert_equal(1, empty(v:none))
44 call assert_equal(1, empty(v:false))
45 call assert_equal(0, empty(v:true))
46
Bram Moolenaar41042f32017-03-09 12:09:32 +010047 if has('channel')
48 call assert_equal(1, empty(test_null_channel()))
49 endif
50 if has('job')
51 call assert_equal(1, empty(test_null_job()))
52 endif
53
Bram Moolenaar24c2e482017-01-29 15:45:12 +010054 call assert_equal(0, empty(function('Test_empty')))
55endfunc
56
57func Test_len()
58 call assert_equal(1, len(0))
59 call assert_equal(2, len(12))
60
61 call assert_equal(0, len(''))
62 call assert_equal(2, len('ab'))
63
64 call assert_equal(0, len([]))
65 call assert_equal(2, len([2, 1]))
66
67 call assert_equal(0, len({}))
68 call assert_equal(2, len({'a': 1, 'b': 2}))
69
70 call assert_fails('call len(v:none)', 'E701:')
71 call assert_fails('call len({-> 0})', 'E701:')
72endfunc
73
74func Test_max()
75 call assert_equal(0, max([]))
76 call assert_equal(2, max([2]))
77 call assert_equal(2, max([1, 2]))
78 call assert_equal(2, max([1, 2, v:null]))
79
80 call assert_equal(0, max({}))
81 call assert_equal(2, max({'a':1, 'b':2}))
82
83 call assert_fails('call max(1)', 'E712:')
84 call assert_fails('call max(v:none)', 'E712:')
85endfunc
86
87func Test_min()
88 call assert_equal(0, min([]))
89 call assert_equal(2, min([2]))
90 call assert_equal(1, min([1, 2]))
91 call assert_equal(0, min([1, 2, v:null]))
92
93 call assert_equal(0, min({}))
94 call assert_equal(1, min({'a':1, 'b':2}))
95
96 call assert_fails('call min(1)', 'E712:')
97 call assert_fails('call min(v:none)', 'E712:')
98endfunc
99
Bram Moolenaar42ab17b2018-05-20 14:11:10 +0200100func Test_strwidth()
101 for aw in ['single', 'double']
102 exe 'set ambiwidth=' . aw
103 call assert_equal(0, strwidth(''))
104 call assert_equal(1, strwidth("\t"))
105 call assert_equal(3, strwidth('Vim'))
106 call assert_equal(4, strwidth(1234))
107 call assert_equal(5, strwidth(-1234))
108
Bram Moolenaar30276f22019-01-24 17:59:39 +0100109 call assert_equal(2, strwidth('😉'))
110 call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde'))
111 call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße'))
Bram Moolenaar42ab17b2018-05-20 14:11:10 +0200112
113 call assert_fails('call strwidth({->0})', 'E729:')
114 call assert_fails('call strwidth([])', 'E730:')
115 call assert_fails('call strwidth({})', 'E731:')
116 call assert_fails('call strwidth(1.2)', 'E806:')
117 endfor
118
119 set ambiwidth&
120endfunc
121
Bram Moolenaar08243d22017-01-10 16:12:29 +0100122func Test_str2nr()
123 call assert_equal(0, str2nr(''))
124 call assert_equal(1, str2nr('1'))
125 call assert_equal(1, str2nr(' 1 '))
126
127 call assert_equal(1, str2nr('+1'))
128 call assert_equal(1, str2nr('+ 1'))
129 call assert_equal(1, str2nr(' + 1 '))
130
131 call assert_equal(-1, str2nr('-1'))
132 call assert_equal(-1, str2nr('- 1'))
133 call assert_equal(-1, str2nr(' - 1 '))
134
135 call assert_equal(123456789, str2nr('123456789'))
136 call assert_equal(-123456789, str2nr('-123456789'))
Bram Moolenaar24c2e482017-01-29 15:45:12 +0100137
138 call assert_equal(5, str2nr('101', 2))
139 call assert_equal(5, str2nr('0b101', 2))
140 call assert_equal(5, str2nr('0B101', 2))
141 call assert_equal(-5, str2nr('-101', 2))
142 call assert_equal(-5, str2nr('-0b101', 2))
143 call assert_equal(-5, str2nr('-0B101', 2))
144
145 call assert_equal(65, str2nr('101', 8))
146 call assert_equal(65, str2nr('0101', 8))
147 call assert_equal(-65, str2nr('-101', 8))
148 call assert_equal(-65, str2nr('-0101', 8))
149
150 call assert_equal(11259375, str2nr('abcdef', 16))
151 call assert_equal(11259375, str2nr('ABCDEF', 16))
152 call assert_equal(-11259375, str2nr('-ABCDEF', 16))
153 call assert_equal(11259375, str2nr('0xabcdef', 16))
154 call assert_equal(11259375, str2nr('0Xabcdef', 16))
155 call assert_equal(11259375, str2nr('0XABCDEF', 16))
156 call assert_equal(-11259375, str2nr('-0xABCDEF', 16))
157
158 call assert_equal(0, str2nr('0x10'))
159 call assert_equal(0, str2nr('0b10'))
160 call assert_equal(1, str2nr('12', 2))
161 call assert_equal(1, str2nr('18', 8))
162 call assert_equal(1, str2nr('1g', 16))
163
164 call assert_equal(0, str2nr(v:null))
165 call assert_equal(0, str2nr(v:none))
166
167 call assert_fails('call str2nr([])', 'E730:')
168 call assert_fails('call str2nr({->2})', 'E729:')
169 call assert_fails('call str2nr(1.2)', 'E806:')
170 call assert_fails('call str2nr(10, [])', 'E474:')
171endfunc
172
173func Test_strftime()
174 if !exists('*strftime')
175 return
176 endif
177 " Format of strftime() depends on system. We assume
178 " that basic formats tested here are available and
179 " identical on all systems which support strftime().
180 "
181 " The 2nd parameter of strftime() is a local time, so the output day
182 " of strftime() can be 17 or 18, depending on timezone.
183 call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512))
184 "
185 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'))
186
187 call assert_fails('call strftime([])', 'E730:')
188 call assert_fails('call strftime("%Y", [])', 'E745:')
189endfunc
190
Bram Moolenaardce1e892019-02-10 23:18:53 +0100191func Test_resolve_unix()
Bram Moolenaar26109902018-10-06 15:43:17 +0200192 if !has('unix')
193 return
194 endif
195
196 " Xlink1 -> Xlink2
197 " Xlink2 -> Xlink3
198 silent !ln -s -f Xlink2 Xlink1
199 silent !ln -s -f Xlink3 Xlink2
200 call assert_equal('Xlink3', resolve('Xlink1'))
201 call assert_equal('./Xlink3', resolve('./Xlink1'))
202 call assert_equal('Xlink3/', resolve('Xlink2/'))
203 " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?!
204 "call assert_equal('Xlink3/', resolve('Xlink1/'))
205 "call assert_equal('./Xlink3/', resolve('./Xlink1/'))
206 "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/'))
207 call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1'))
208
209 " Test resolve() with a symlink cycle.
210 " Xlink1 -> Xlink2
211 " Xlink2 -> Xlink3
212 " Xlink3 -> Xlink1
213 silent !ln -s -f Xlink1 Xlink3
214 call assert_fails('call resolve("Xlink1")', 'E655:')
215 call assert_fails('call resolve("./Xlink1")', 'E655:')
216 call assert_fails('call resolve("Xlink2")', 'E655:')
217 call assert_fails('call resolve("Xlink3")', 'E655:')
218 call delete('Xlink1')
219 call delete('Xlink2')
220 call delete('Xlink3')
221
222 silent !ln -s -f Xdir//Xfile Xlink
223 call assert_equal('Xdir/Xfile', resolve('Xlink'))
224 call delete('Xlink')
225
226 silent !ln -s -f Xlink2/ Xlink1
227 call assert_equal('Xlink2', resolve('Xlink1'))
228 call assert_equal('Xlink2/', resolve('Xlink1/'))
229 call delete('Xlink1')
230
231 silent !ln -s -f ./Xlink2 Xlink1
232 call assert_equal('Xlink2', resolve('Xlink1'))
233 call assert_equal('./Xlink2', resolve('./Xlink1'))
234 call delete('Xlink1')
235endfunc
236
Bram Moolenaardce1e892019-02-10 23:18:53 +0100237func s:normalize_fname(fname)
238 let ret = substitute(a:fname, '\', '/', 'g')
239 let ret = substitute(ret, '//', '/', 'g')
240 let ret = tolower(ret)
241endfunc
242
243func Test_resolve_win32()
244 if !has('win32')
245 return
246 endif
247
248 " test for shortcut file
249 if executable('cscript')
250 new Xfile
251 wq
252 call writefile([
253 \ 'Set fs = CreateObject("Scripting.FileSystemObject")',
254 \ 'Set ws = WScript.CreateObject("WScript.Shell")',
255 \ 'Set shortcut = ws.CreateShortcut("Xlink.lnk")',
256 \ 'shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile")',
257 \ 'shortcut.Save'
258 \], 'link.vbs')
259 silent !cscript link.vbs
260 call delete('link.vbs')
261 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk')))
262 call delete('Xfile')
263
264 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk')))
265 call delete('Xlink.lnk')
266 else
267 echomsg 'skipped test for shortcut file'
268 endif
269
270 " remove files
271 call delete('Xlink')
272 call delete('Xdir', 'd')
273 call delete('Xfile')
274
275 " test for symbolic link to a file
276 new Xfile
277 wq
278 silent !mklink Xlink Xfile
279 if !v:shell_error
280 call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink')))
281 call delete('Xlink')
282 else
283 echomsg 'skipped test for symbolic link to a file'
284 endif
285 call delete('Xfile')
286
287 " test for junction to a directory
288 call mkdir('Xdir')
289 silent !mklink /J Xlink Xdir
290 if !v:shell_error
291 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
292
293 call delete('Xdir', 'd')
294
295 " test for junction already removed
296 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
297 call delete('Xlink')
298 else
299 echomsg 'skipped test for junction to a directory'
300 call delete('Xdir', 'd')
301 endif
302
303 " test for symbolic link to a directory
304 call mkdir('Xdir')
305 silent !mklink /D Xlink Xdir
306 if !v:shell_error
307 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
308
309 call delete('Xdir', 'd')
310
311 " test for symbolic link already removed
312 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
313 call delete('Xlink')
314 else
315 echomsg 'skipped test for symbolic link to a directory'
316 call delete('Xdir', 'd')
317 endif
318
319 " test for buffer name
320 new Xfile
321 wq
322 silent !mklink Xlink Xfile
323 if !v:shell_error
324 edit Xlink
325 call assert_equal('Xlink', bufname('%'))
326 call delete('Xlink')
327 bw!
328 else
329 echomsg 'skipped test for buffer name'
330 endif
331 call delete('Xfile')
332endfunc
333
Bram Moolenaar24c2e482017-01-29 15:45:12 +0100334func Test_simplify()
335 call assert_equal('', simplify(''))
336 call assert_equal('/', simplify('/'))
337 call assert_equal('/', simplify('/.'))
338 call assert_equal('/', simplify('/..'))
339 call assert_equal('/...', simplify('/...'))
340 call assert_equal('./dir/file', simplify('./dir/file'))
341 call assert_equal('./dir/file', simplify('.///dir//file'))
342 call assert_equal('./dir/file', simplify('./dir/./file'))
343 call assert_equal('./file', simplify('./dir/../file'))
344 call assert_equal('../dir/file', simplify('dir/../../dir/file'))
345 call assert_equal('./file', simplify('dir/.././file'))
346
347 call assert_fails('call simplify({->0})', 'E729:')
348 call assert_fails('call simplify([])', 'E730:')
349 call assert_fails('call simplify({})', 'E731:')
350 call assert_fails('call simplify(1.2)', 'E806:')
Bram Moolenaar08243d22017-01-10 16:12:29 +0100351endfunc
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100352
Bram Moolenaarbfde0b42018-08-08 22:27:31 +0200353func Test_pathshorten()
354 call assert_equal('', pathshorten(''))
355 call assert_equal('foo', pathshorten('foo'))
356 call assert_equal('/foo', pathshorten('/foo'))
357 call assert_equal('f/', pathshorten('foo/'))
358 call assert_equal('f/bar', pathshorten('foo/bar'))
359 call assert_equal('f/b/foobar', pathshorten('foo/bar/foobar'))
360 call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar'))
361 call assert_equal('.f/bar', pathshorten('.foo/bar'))
362 call assert_equal('~f/bar', pathshorten('~foo/bar'))
363 call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
364 call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
365 call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
366endfunc
367
Bram Moolenaarc7d16dc2017-11-18 20:32:03 +0100368func Test_strpart()
369 call assert_equal('de', strpart('abcdefg', 3, 2))
370 call assert_equal('ab', strpart('abcdefg', -2, 4))
371 call assert_equal('abcdefg', strpart('abcdefg', -2))
372 call assert_equal('fg', strpart('abcdefg', 5, 4))
373 call assert_equal('defg', strpart('abcdefg', 3))
374
Bram Moolenaar30276f22019-01-24 17:59:39 +0100375 call assert_equal('lép', strpart('éléphant', 2, 4))
376 call assert_equal('léphant', strpart('éléphant', 2))
Bram Moolenaarc7d16dc2017-11-18 20:32:03 +0100377endfunc
378
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100379func Test_tolower()
380 call assert_equal("", tolower(""))
381
382 " Test with all printable ASCII characters.
383 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
384 \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
385
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100386 " Test with a few uppercase diacritics.
387 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
388 call assert_equal("bḃḇ", tolower("BḂḆ"))
389 call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ"))
390 call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ"))
391 call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ"))
392 call assert_equal("f ", tolower("F "))
393 call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ"))
394 call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ"))
395 call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ"))
396 call assert_equal("jĵ", tolower("JĴ"))
397 call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ"))
398 call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ"))
399 call assert_equal("mḿṁ", tolower("MḾṀ"))
400 call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ"))
401 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
402 call assert_equal("pṕṗ", tolower("PṔṖ"))
403 call assert_equal("q", tolower("Q"))
404 call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ"))
405 call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ"))
406 call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ"))
407 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
408 call assert_equal("v", tolower("V"))
409 call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ"))
410 call assert_equal("xẋẍ", tolower("XẊẌ"))
411 call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ"))
412 call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ"))
413
414 " Test with a few lowercase diacritics, which should remain unchanged.
415 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả"))
416 call assert_equal("bḃḇ", tolower("bḃḇ"))
417 call assert_equal("cçćĉċč", tolower("cçćĉċč"))
418 call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ"))
419 call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ"))
420 call assert_equal("fḟ", tolower("fḟ"))
421 call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ"))
422 call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ"))
423 call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ"))
424 call assert_equal("jĵǰ", tolower("jĵǰ"))
425 call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ"))
426 call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ"))
427 call assert_equal("mḿṁ ", tolower("mḿṁ "))
428 call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ"))
429 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ"))
430 call assert_equal("pṕṗ", tolower("pṕṗ"))
431 call assert_equal("q", tolower("q"))
432 call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ"))
433 call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ"))
434 call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ"))
435 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ"))
436 call assert_equal("vṽ", tolower("vṽ"))
437 call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ"))
438 call assert_equal("ẋẍ", tolower("ẋẍ"))
439 call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ"))
440 call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ"))
441
442 " According to https://twitter.com/jifa/status/625776454479970304
443 " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase
444 " in length (2 to 3 bytes) when lowercased. So let's test them.
445 call assert_equal(" ", tolower("Ⱥ Ⱦ"))
Bram Moolenaare6640ad2017-12-22 21:06:56 +0100446
447 " This call to tolower with invalid utf8 sequence used to cause access to
448 " invalid memory.
449 call tolower("\xC0\x80\xC0")
450 call tolower("123\xC0\x80\xC0")
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100451endfunc
452
453func Test_toupper()
454 call assert_equal("", toupper(""))
455
456 " Test with all printable ASCII characters.
457 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~',
458 \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
459
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100460 " Test with a few lowercase diacritics.
461 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả"))
462 call assert_equal("BḂḆ", toupper("bḃḇ"))
463 call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč"))
464 call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ"))
465 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ"))
466 call assert_equal("F", toupper("f"))
467 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ"))
468 call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ"))
469 call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ"))
470 call assert_equal("JĴǰ", toupper("jĵǰ"))
471 call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ"))
472 call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ"))
473 call assert_equal("MḾṀ ", toupper("mḿṁ "))
474 call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ"))
475 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ"))
476 call assert_equal("PṔṖ", toupper("pṕṗ"))
477 call assert_equal("Q", toupper("q"))
478 call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ"))
479 call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ"))
480 call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ"))
481 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ"))
482 call assert_equal("V", toupper("v"))
483 call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ"))
484 call assert_equal("ẊẌ", toupper("ẋẍ"))
485 call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ"))
486 call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ"))
487
488 " Test that uppercase diacritics, which should remain unchanged.
489 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
490 call assert_equal("BḂḆ", toupper("BḂḆ"))
491 call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ"))
492 call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ"))
493 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ"))
494 call assert_equal("FḞ ", toupper("FḞ "))
495 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ"))
496 call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ"))
497 call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ"))
498 call assert_equal("JĴ", toupper("JĴ"))
499 call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ"))
500 call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ"))
501 call assert_equal("MḾṀ", toupper("MḾṀ"))
502 call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ"))
503 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
504 call assert_equal("PṔṖ", toupper("PṔṖ"))
505 call assert_equal("Q", toupper("Q"))
506 call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ"))
507 call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ"))
508 call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ"))
509 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
510 call assert_equal("VṼ", toupper("VṼ"))
511 call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ"))
512 call assert_equal("XẊẌ", toupper("XẊẌ"))
513 call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ"))
514 call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ"))
515
Bram Moolenaar24c2e482017-01-29 15:45:12 +0100516 call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ"))
Bram Moolenaare6640ad2017-12-22 21:06:56 +0100517
518 " This call to toupper with invalid utf8 sequence used to cause access to
519 " invalid memory.
520 call toupper("\xC0\x80\xC0")
521 call toupper("123\xC0\x80\xC0")
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100522endfunc
523
Bram Moolenaare90858d2017-02-01 17:24:34 +0100524" Tests for the mode() function
525let current_modes = ''
Bram Moolenaarffea8c92017-03-13 20:37:15 +0100526func Save_mode()
Bram Moolenaare90858d2017-02-01 17:24:34 +0100527 let g:current_modes = mode(0) . '-' . mode(1)
528 return ''
529endfunc
Bram Moolenaarcc5b22b2017-01-26 22:51:56 +0100530
Bram Moolenaarffea8c92017-03-13 20:37:15 +0100531func Test_mode()
Bram Moolenaare90858d2017-02-01 17:24:34 +0100532 new
533 call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
534
Bram Moolenaarffea8c92017-03-13 20:37:15 +0100535 " Only complete from the current buffer.
536 set complete=.
537
Bram Moolenaare90858d2017-02-01 17:24:34 +0100538 inoremap <F2> <C-R>=Save_mode()<CR>
539
540 normal! 3G
541 exe "normal i\<F2>\<Esc>"
542 call assert_equal('i-i', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100543 " i_CTRL-P: Multiple matches
Bram Moolenaare90858d2017-02-01 17:24:34 +0100544 exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u"
545 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100546 " i_CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100547 exe "normal iBro\<C-P>\<F2>\<Esc>u"
548 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100549 " i_CTRL-X
Bram Moolenaare90858d2017-02-01 17:24:34 +0100550 exe "normal iBa\<C-X>\<F2>\<Esc>u"
551 call assert_equal('i-ix', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100552 " i_CTRL-X CTRL-P: Multiple matches
Bram Moolenaare90858d2017-02-01 17:24:34 +0100553 exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u"
554 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100555 " i_CTRL-X CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100556 exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u"
557 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100558 " i_CTRL-X CTRL-P + CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100559 exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
560 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100561 " i_CTRL-X CTRL-L: Multiple matches
562 exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u"
563 call assert_equal('i-ic', g:current_modes)
564 " i_CTRL-X CTRL-L: Single match
565 exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u"
566 call assert_equal('i-ic', g:current_modes)
567 " i_CTRL-P: No match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100568 exe "normal iCom\<C-P>\<F2>\<Esc>u"
569 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100570 " i_CTRL-X CTRL-P: No match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100571 exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u"
572 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100573 " i_CTRL-X CTRL-L: No match
574 exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u"
575 call assert_equal('i-ic', g:current_modes)
Bram Moolenaare90858d2017-02-01 17:24:34 +0100576
Bram Moolenaare971df32017-02-05 14:15:29 +0100577 " R_CTRL-P: Multiple matches
Bram Moolenaare90858d2017-02-01 17:24:34 +0100578 exe "normal RBa\<C-P>\<F2>\<Esc>u"
579 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100580 " R_CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100581 exe "normal RBro\<C-P>\<F2>\<Esc>u"
582 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100583 " R_CTRL-X
Bram Moolenaare90858d2017-02-01 17:24:34 +0100584 exe "normal RBa\<C-X>\<F2>\<Esc>u"
585 call assert_equal('R-Rx', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100586 " R_CTRL-X CTRL-P: Multiple matches
Bram Moolenaare90858d2017-02-01 17:24:34 +0100587 exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u"
588 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100589 " R_CTRL-X CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100590 exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u"
591 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100592 " R_CTRL-X CTRL-P + CTRL-P: Single match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100593 exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
594 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100595 " R_CTRL-X CTRL-L: Multiple matches
596 exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u"
597 call assert_equal('R-Rc', g:current_modes)
598 " R_CTRL-X CTRL-L: Single match
599 exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u"
600 call assert_equal('R-Rc', g:current_modes)
601 " R_CTRL-P: No match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100602 exe "normal RCom\<C-P>\<F2>\<Esc>u"
603 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100604 " R_CTRL-X CTRL-P: No match
Bram Moolenaare90858d2017-02-01 17:24:34 +0100605 exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u"
606 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare971df32017-02-05 14:15:29 +0100607 " R_CTRL-X CTRL-L: No match
608 exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u"
609 call assert_equal('R-Rc', g:current_modes)
Bram Moolenaare90858d2017-02-01 17:24:34 +0100610
611 call assert_equal('n', mode(0))
612 call assert_equal('n', mode(1))
613
Bram Moolenaar612cc382018-07-29 15:34:26 +0200614 " i_CTRL-O
615 exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>"
616 call assert_equal("n-niI", g:current_modes)
617
618 " R_CTRL-O
619 exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>"
620 call assert_equal("n-niR", g:current_modes)
621
622 " gR_CTRL-O
623 exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>"
624 call assert_equal("n-niV", g:current_modes)
625
Bram Moolenaare90858d2017-02-01 17:24:34 +0100626 " How to test operator-pending mode?
627
628 call feedkeys("v", 'xt')
629 call assert_equal('v', mode())
630 call assert_equal('v', mode(1))
631 call feedkeys("\<Esc>V", 'xt')
632 call assert_equal('V', mode())
633 call assert_equal('V', mode(1))
634 call feedkeys("\<Esc>\<C-V>", 'xt')
635 call assert_equal("\<C-V>", mode())
636 call assert_equal("\<C-V>", mode(1))
637 call feedkeys("\<Esc>", 'xt')
638
639 call feedkeys("gh", 'xt')
640 call assert_equal('s', mode())
641 call assert_equal('s', mode(1))
642 call feedkeys("\<Esc>gH", 'xt')
643 call assert_equal('S', mode())
644 call assert_equal('S', mode(1))
645 call feedkeys("\<Esc>g\<C-H>", 'xt')
646 call assert_equal("\<C-S>", mode())
647 call assert_equal("\<C-S>", mode(1))
648 call feedkeys("\<Esc>", 'xt')
649
650 call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt')
651 call assert_equal('c-c', g:current_modes)
652 call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt')
653 call assert_equal('c-cv', g:current_modes)
654 " How to test Ex mode?
655
656 bwipe!
657 iunmap <F2>
Bram Moolenaarffea8c92017-03-13 20:37:15 +0100658 set complete&
Bram Moolenaare90858d2017-02-01 17:24:34 +0100659endfunc
Bram Moolenaar79518e22017-02-17 16:31:35 +0100660
661func Test_getbufvar()
662 let bnr = bufnr('%')
663 let b:var_num = '1234'
664 let def_num = '5678'
665 call assert_equal('1234', getbufvar(bnr, 'var_num'))
666 call assert_equal('1234', getbufvar(bnr, 'var_num', def_num))
667
668 let bd = getbufvar(bnr, '')
669 call assert_equal('1234', bd['var_num'])
670 call assert_true(exists("bd['changedtick']"))
671 call assert_equal(2, len(bd))
672
673 let bd2 = getbufvar(bnr, '', def_num)
674 call assert_equal(bd, bd2)
675
676 unlet b:var_num
677 call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num))
678 call assert_equal('', getbufvar(bnr, 'var_num'))
679
680 let bd = getbufvar(bnr, '')
681 call assert_equal(1, len(bd))
682 let bd = getbufvar(bnr, '',def_num)
683 call assert_equal(1, len(bd))
684
Bram Moolenaar4520d442017-03-19 16:09:46 +0100685 call assert_equal('', getbufvar(9999, ''))
686 call assert_equal(def_num, getbufvar(9999, '', def_num))
Bram Moolenaar79518e22017-02-17 16:31:35 +0100687 unlet def_num
688
Bram Moolenaar507647d2017-02-17 16:43:49 +0100689 call assert_equal(0, getbufvar(bnr, '&autoindent'))
690 call assert_equal(0, getbufvar(bnr, '&autoindent', 1))
Bram Moolenaar79518e22017-02-17 16:31:35 +0100691
692 " Open new window with forced option values
693 set fileformats=unix,dos
694 new ++ff=dos ++bin ++enc=iso-8859-2
695 call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat'))
696 call assert_equal(1, getbufvar(bufnr('%'), '&bin'))
697 call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
698 close
699
700 set fileformats&
701endfunc
Bram Moolenaarcaf64342017-03-02 22:11:33 +0100702
Bram Moolenaar41042f32017-03-09 12:09:32 +0100703func Test_last_buffer_nr()
704 call assert_equal(bufnr('$'), last_buffer_nr())
705endfunc
706
707func Test_stridx()
708 call assert_equal(-1, stridx('', 'l'))
709 call assert_equal(0, stridx('', ''))
710 call assert_equal(0, stridx('hello', ''))
711 call assert_equal(-1, stridx('hello', 'L'))
712 call assert_equal(2, stridx('hello', 'l', -1))
713 call assert_equal(2, stridx('hello', 'l', 0))
714 call assert_equal(2, stridx('hello', 'l', 1))
715 call assert_equal(3, stridx('hello', 'l', 3))
716 call assert_equal(-1, stridx('hello', 'l', 4))
717 call assert_equal(-1, stridx('hello', 'l', 10))
718 call assert_equal(2, stridx('hello', 'll'))
719 call assert_equal(-1, stridx('hello', 'hello world'))
720endfunc
721
722func Test_strridx()
723 call assert_equal(-1, strridx('', 'l'))
724 call assert_equal(0, strridx('', ''))
725 call assert_equal(5, strridx('hello', ''))
726 call assert_equal(-1, strridx('hello', 'L'))
727 call assert_equal(3, strridx('hello', 'l'))
728 call assert_equal(3, strridx('hello', 'l', 10))
729 call assert_equal(3, strridx('hello', 'l', 3))
730 call assert_equal(2, strridx('hello', 'l', 2))
731 call assert_equal(-1, strridx('hello', 'l', 1))
732 call assert_equal(-1, strridx('hello', 'l', 0))
733 call assert_equal(-1, strridx('hello', 'l', -1))
734 call assert_equal(2, strridx('hello', 'll'))
735 call assert_equal(-1, strridx('hello', 'hello world'))
736endfunc
737
Bram Moolenaar1190cf62017-09-14 14:31:18 +0200738func Test_match_func()
739 call assert_equal(4, match('testing', 'ing'))
740 call assert_equal(4, match('testing', 'ing', 2))
741 call assert_equal(-1, match('testing', 'ing', 5))
742 call assert_equal(-1, match('testing', 'ing', 8))
743 call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing'))
744 call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img'))
745endfunc
746
Bram Moolenaar41042f32017-03-09 12:09:32 +0100747func Test_matchend()
748 call assert_equal(7, matchend('testing', 'ing'))
749 call assert_equal(7, matchend('testing', 'ing', 2))
750 call assert_equal(-1, matchend('testing', 'ing', 5))
Bram Moolenaar1190cf62017-09-14 14:31:18 +0200751 call assert_equal(-1, matchend('testing', 'ing', 8))
752 call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing'))
753 call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img'))
754endfunc
755
756func Test_matchlist()
757 call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)'))
758 call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2))
759 call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4))
760endfunc
761
762func Test_matchstr()
763 call assert_equal('ing', matchstr('testing', 'ing'))
764 call assert_equal('ing', matchstr('testing', 'ing', 2))
765 call assert_equal('', matchstr('testing', 'ing', 5))
766 call assert_equal('', matchstr('testing', 'ing', 8))
767 call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing'))
768 call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img'))
769endfunc
770
771func Test_matchstrpos()
772 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
773 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2))
774 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
775 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
776 call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
777 call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
Bram Moolenaar41042f32017-03-09 12:09:32 +0100778endfunc
779
780func Test_nextnonblank_prevnonblank()
781 new
782insert
783This
784
785
786is
787
788a
789Test
790.
791 call assert_equal(0, nextnonblank(-1))
792 call assert_equal(0, nextnonblank(0))
793 call assert_equal(1, nextnonblank(1))
794 call assert_equal(4, nextnonblank(2))
795 call assert_equal(4, nextnonblank(3))
796 call assert_equal(4, nextnonblank(4))
797 call assert_equal(6, nextnonblank(5))
798 call assert_equal(6, nextnonblank(6))
799 call assert_equal(7, nextnonblank(7))
800 call assert_equal(0, nextnonblank(8))
801
802 call assert_equal(0, prevnonblank(-1))
803 call assert_equal(0, prevnonblank(0))
804 call assert_equal(1, prevnonblank(1))
805 call assert_equal(1, prevnonblank(2))
806 call assert_equal(1, prevnonblank(3))
807 call assert_equal(4, prevnonblank(4))
808 call assert_equal(4, prevnonblank(5))
809 call assert_equal(6, prevnonblank(6))
810 call assert_equal(7, prevnonblank(7))
811 call assert_equal(0, prevnonblank(8))
812 bw!
813endfunc
814
815func Test_byte2line_line2byte()
816 new
Bram Moolenaarc26f7c62018-08-20 22:53:04 +0200817 set endofline
Bram Moolenaar41042f32017-03-09 12:09:32 +0100818 call setline(1, ['a', 'bc', 'd'])
819
820 set fileformat=unix
821 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
822 \ map(range(-1, 8), 'byte2line(v:val)'))
823 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
824 \ map(range(-1, 5), 'line2byte(v:val)'))
825
826 set fileformat=mac
827 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
828 \ map(range(-1, 8), 'byte2line(v:val)'))
829 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
830 \ map(range(-1, 5), 'line2byte(v:val)'))
831
832 set fileformat=dos
833 call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1],
834 \ map(range(-1, 11), 'byte2line(v:val)'))
835 call assert_equal([-1, -1, 1, 4, 8, 11, -1],
836 \ map(range(-1, 5), 'line2byte(v:val)'))
837
Bram Moolenaarc26f7c62018-08-20 22:53:04 +0200838 bw!
839 set noendofline nofixendofline
840 normal a-
841 for ff in ["unix", "mac", "dos"]
842 let &fileformat = ff
843 call assert_equal(1, line2byte(1))
844 call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte).
845 endfor
846
847 set endofline& fixendofline& fileformat&
Bram Moolenaar41042f32017-03-09 12:09:32 +0100848 bw!
849endfunc
850
851func Test_count()
852 let l = ['a', 'a', 'A', 'b']
853 call assert_equal(2, count(l, 'a'))
854 call assert_equal(1, count(l, 'A'))
855 call assert_equal(1, count(l, 'b'))
856 call assert_equal(0, count(l, 'B'))
857
858 call assert_equal(2, count(l, 'a', 0))
859 call assert_equal(1, count(l, 'A', 0))
860 call assert_equal(1, count(l, 'b', 0))
861 call assert_equal(0, count(l, 'B', 0))
862
863 call assert_equal(3, count(l, 'a', 1))
864 call assert_equal(3, count(l, 'A', 1))
865 call assert_equal(1, count(l, 'b', 1))
866 call assert_equal(1, count(l, 'B', 1))
867 call assert_equal(0, count(l, 'c', 1))
868
869 call assert_equal(1, count(l, 'a', 0, 1))
870 call assert_equal(2, count(l, 'a', 1, 1))
871 call assert_fails('call count(l, "a", 0, 10)', 'E684:')
872
873 let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'}
874 call assert_equal(2, count(d, 'a'))
875 call assert_equal(1, count(d, 'A'))
876 call assert_equal(1, count(d, 'b'))
877 call assert_equal(0, count(d, 'B'))
878
879 call assert_equal(2, count(d, 'a', 0))
880 call assert_equal(1, count(d, 'A', 0))
881 call assert_equal(1, count(d, 'b', 0))
882 call assert_equal(0, count(d, 'B', 0))
883
884 call assert_equal(3, count(d, 'a', 1))
885 call assert_equal(3, count(d, 'A', 1))
886 call assert_equal(1, count(d, 'b', 1))
887 call assert_equal(1, count(d, 'B', 1))
888 call assert_equal(0, count(d, 'c', 1))
889
890 call assert_fails('call count(d, "a", 0, 1)', 'E474:')
Bram Moolenaar9966b212017-07-28 16:46:57 +0200891
892 call assert_equal(0, count("foo", "bar"))
893 call assert_equal(1, count("foo", "oo"))
894 call assert_equal(2, count("foo", "o"))
895 call assert_equal(0, count("foo", "O"))
896 call assert_equal(2, count("foo", "O", 1))
897 call assert_equal(2, count("fooooo", "oo"))
Bram Moolenaar338e47f2017-12-19 11:55:26 +0100898 call assert_equal(0, count("foo", ""))
Bram Moolenaar41042f32017-03-09 12:09:32 +0100899endfunc
900
901func Test_changenr()
902 new Xchangenr
903 call assert_equal(0, changenr())
904 norm ifoo
905 call assert_equal(1, changenr())
906 set undolevels=10
907 norm Sbar
908 call assert_equal(2, changenr())
909 undo
910 call assert_equal(1, changenr())
911 redo
912 call assert_equal(2, changenr())
913 bw!
914 set undolevels&
915endfunc
916
917func Test_filewritable()
918 new Xfilewritable
919 write!
920 call assert_equal(1, filewritable('Xfilewritable'))
921
922 call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----'))
923 call assert_equal(0, filewritable('Xfilewritable'))
924
925 call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----'))
926 call assert_equal(1, filewritable('Xfilewritable'))
927
928 call assert_equal(0, filewritable('doesnotexist'))
929
930 call delete('Xfilewritable')
931 bw!
932endfunc
933
Bram Moolenaar82956662018-10-06 15:18:45 +0200934func Test_Executable()
935 if has('win32')
936 call assert_equal(1, executable('notepad'))
937 call assert_equal(1, executable('notepad.exe'))
938 call assert_equal(0, executable('notepad.exe.exe'))
939 call assert_equal(0, executable('shell32.dll'))
940 call assert_equal(0, executable('win.ini'))
941 elseif has('unix')
942 call assert_equal(1, executable('cat'))
Bram Moolenaara05a0d32018-10-07 18:43:05 +0200943 call assert_equal(0, executable('nodogshere'))
Bram Moolenaar82956662018-10-06 15:18:45 +0200944 endif
945endfunc
946
Bram Moolenaar41042f32017-03-09 12:09:32 +0100947func Test_hostname()
948 let hostname_vim = hostname()
949 if has('unix')
950 let hostname_system = systemlist('uname -n')[0]
951 call assert_equal(hostname_vim, hostname_system)
952 endif
953endfunc
954
955func Test_getpid()
956 " getpid() always returns the same value within a vim instance.
957 call assert_equal(getpid(), getpid())
958 if has('unix')
959 call assert_equal(systemlist('echo $PPID')[0], string(getpid()))
960 endif
961endfunc
962
963func Test_hlexists()
964 call assert_equal(0, hlexists('does_not_exist'))
965 call assert_equal(0, hlexists('Number'))
966 call assert_equal(0, highlight_exists('does_not_exist'))
967 call assert_equal(0, highlight_exists('Number'))
968 syntax on
969 call assert_equal(0, hlexists('does_not_exist'))
970 call assert_equal(1, hlexists('Number'))
971 call assert_equal(0, highlight_exists('does_not_exist'))
972 call assert_equal(1, highlight_exists('Number'))
973 syntax off
974endfunc
975
976func Test_col()
977 new
978 call setline(1, 'abcdef')
979 norm gg4|mx6|mY2|
980 call assert_equal(2, col('.'))
981 call assert_equal(7, col('$'))
982 call assert_equal(4, col("'x"))
983 call assert_equal(6, col("'Y"))
984 call assert_equal(2, col([1, 2]))
985 call assert_equal(7, col([1, '$']))
986
987 call assert_equal(0, col(''))
988 call assert_equal(0, col('x'))
989 call assert_equal(0, col([2, '$']))
990 call assert_equal(0, col([1, 100]))
991 call assert_equal(0, col([1]))
992 bw!
993endfunc
994
Bram Moolenaar947b39e2018-07-22 19:36:37 +0200995func Test_inputlist()
996 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx')
997 call assert_equal(1, c)
998 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>2\<cr>", 'tx')
999 call assert_equal(2, c)
1000 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx')
1001 call assert_equal(3, c)
1002
1003 call assert_fails('call inputlist("")', 'E686:')
1004endfunc
1005
Bram Moolenaarcaf64342017-03-02 22:11:33 +01001006func Test_balloon_show()
Bram Moolenaara0107bd2017-03-02 22:48:01 +01001007 if has('balloon_eval')
1008 " This won't do anything but must not crash either.
1009 call balloon_show('hi!')
1010 endif
Bram Moolenaarcaf64342017-03-02 22:11:33 +01001011endfunc
Bram Moolenaar2c90d512017-03-18 22:35:30 +01001012
1013func Test_setbufvar_options()
1014 " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the
1015 " window layout.
1016 call assert_equal(1, winnr('$'))
1017 split dummy_preview
1018 resize 2
1019 set winfixheight winfixwidth
1020 let prev_id = win_getid()
1021
1022 wincmd j
1023 let wh = winheight('.')
1024 let dummy_buf = bufnr('dummy_buf1', v:true)
1025 call setbufvar(dummy_buf, '&buftype', 'nofile')
1026 execute 'belowright vertical split #' . dummy_buf
1027 call assert_equal(wh, winheight('.'))
1028 let dum1_id = win_getid()
1029
1030 wincmd h
1031 let wh = winheight('.')
1032 let dummy_buf = bufnr('dummy_buf2', v:true)
1033 call setbufvar(dummy_buf, '&buftype', 'nofile')
1034 execute 'belowright vertical split #' . dummy_buf
1035 call assert_equal(wh, winheight('.'))
1036
1037 bwipe!
1038 call win_gotoid(prev_id)
1039 bwipe!
1040 call win_gotoid(dum1_id)
1041 bwipe!
1042endfunc
Bram Moolenaard4863aa2017-04-07 19:50:12 +02001043
1044func Test_redo_in_nested_functions()
1045 nnoremap g. :set opfunc=Operator<CR>g@
1046 function Operator( type, ... )
1047 let @x = 'XXX'
1048 execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp'
1049 endfunction
1050
1051 function! Apply()
1052 5,6normal! .
1053 endfunction
1054
1055 new
1056 call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3))
1057 1normal g.i"
1058 call assert_equal('some "XXX" text', getline(1))
1059 3,4normal .
1060 call assert_equal('some "XXX" text', getline(3))
1061 call assert_equal('more "XXX" text', getline(4))
1062 call Apply()
1063 call assert_equal('some "XXX" text', getline(5))
1064 call assert_equal('more "XXX" text', getline(6))
1065 bwipe!
1066
1067 nunmap g.
1068 delfunc Operator
1069 delfunc Apply
1070endfunc
Bram Moolenaar20615522017-06-05 18:46:26 +02001071
1072func Test_shellescape()
1073 let save_shell = &shell
1074 set shell=bash
1075 call assert_equal("'text'", shellescape('text'))
1076 call assert_equal("'te\"xt'", shellescape('te"xt'))
1077 call assert_equal("'te'\\''xt'", shellescape("te'xt"))
1078
1079 call assert_equal("'te%xt'", shellescape("te%xt"))
1080 call assert_equal("'te\\%xt'", shellescape("te%xt", 1))
1081 call assert_equal("'te#xt'", shellescape("te#xt"))
1082 call assert_equal("'te\\#xt'", shellescape("te#xt", 1))
1083 call assert_equal("'te!xt'", shellescape("te!xt"))
1084 call assert_equal("'te\\!xt'", shellescape("te!xt", 1))
1085
1086 call assert_equal("'te\nxt'", shellescape("te\nxt"))
1087 call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1))
1088 set shell=tcsh
1089 call assert_equal("'te\\!xt'", shellescape("te!xt"))
1090 call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1))
1091 call assert_equal("'te\\\nxt'", shellescape("te\nxt"))
1092 call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1))
1093
1094 let &shell = save_shell
1095endfunc
Bram Moolenaar295ac5a2018-03-22 23:04:02 +01001096
1097func Test_trim()
1098 call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B"))
1099 call assert_equal("Testing", trim(" \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"))
1100 call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t"))
1101 call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww"))
1102 call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail"))
1103 call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " "))
1104 call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx"))
1105 call assert_equal("RESERVE", trim("你RESERVE好", "你好"))
1106 call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好"))
1107 call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", ))
1108 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好"))
1109 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes"))
1110 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses"))
1111 call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要"))
1112 call assert_equal("", trim("", ""))
1113 call assert_equal("a", trim("a", ""))
1114 call assert_equal("", trim("", "a"))
1115
1116 let chars = join(map(range(1, 0x20) + [0xa0], {n -> nr2char(n)}), '')
1117 call assert_equal("x", trim(chars . "x" . chars))
1118endfunc
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02001119
1120" Test for reg_recording() and reg_executing()
1121func Test_reg_executing_and_recording()
1122 let s:reg_stat = ''
1123 func s:save_reg_stat()
1124 let s:reg_stat = reg_recording() . ':' . reg_executing()
1125 return ''
1126 endfunc
1127
1128 new
1129 call s:save_reg_stat()
1130 call assert_equal(':', s:reg_stat)
1131 call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt')
1132 call assert_equal('a:', s:reg_stat)
1133 call feedkeys("@a", 'xt')
1134 call assert_equal(':a', s:reg_stat)
1135 call feedkeys("qb@aq", 'xt')
1136 call assert_equal('b:a', s:reg_stat)
1137 call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt')
1138 call assert_equal('":', s:reg_stat)
1139
Bram Moolenaarcce713d2019-03-04 11:40:12 +01001140 " :normal command saves and restores reg_executing
Bram Moolenaarf0fab302019-03-05 12:24:10 +01001141 let s:reg_stat = ''
Bram Moolenaarcce713d2019-03-04 11:40:12 +01001142 let @q = ":call TestFunc()\<CR>:call s:save_reg_stat()\<CR>"
1143 func TestFunc() abort
1144 normal! ia
1145 endfunc
1146 call feedkeys("@q", 'xt')
1147 call assert_equal(':q', s:reg_stat)
1148 delfunc TestFunc
1149
Bram Moolenaarf0fab302019-03-05 12:24:10 +01001150 " getchar() command saves and restores reg_executing
1151 map W :call TestFunc()<CR>
1152 let @q = "W"
1153 func TestFunc() abort
1154 let g:reg1 = reg_executing()
1155 let g:typed = getchar(0)
1156 let g:reg2 = reg_executing()
1157 endfunc
1158 call feedkeys("@qy", 'xt')
1159 call assert_equal(char2nr("y"), g:typed)
1160 call assert_equal('q', g:reg1)
1161 call assert_equal('q', g:reg2)
1162 delfunc TestFunc
1163 unmap W
1164 unlet g:typed
1165 unlet g:reg1
1166 unlet g:reg2
1167
Bram Moolenaar0b6d9112018-05-22 20:35:17 +02001168 bwipe!
1169 delfunc s:save_reg_stat
1170 unlet s:reg_stat
1171endfunc
Bram Moolenaar1ceebb42018-06-19 19:46:06 +02001172
1173func Test_libcall_libcallnr()
1174 if !has('libcall')
1175 return
1176 endif
1177
1178 if has('win32')
1179 let libc = 'msvcrt.dll'
1180 elseif has('mac')
1181 let libc = 'libSystem.B.dylib'
Bram Moolenaar39536dd2019-01-29 22:58:21 +01001182 elseif executable('ldd')
1183 let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>')
1184 endif
1185 if get(l:, 'libc', '') ==# ''
Bram Moolenaar1ceebb42018-06-19 19:46:06 +02001186 " On Unix, libc.so can be in various places.
Bram Moolenaar39536dd2019-01-29 22:58:21 +01001187 if has('linux')
1188 " There is not documented but regarding the 1st argument of glibc's
1189 " dlopen an empty string and nullptr are equivalent, so using an empty
1190 " string for the 1st argument of libcall allows to call functions.
1191 let libc = ''
1192 elseif has('sun')
1193 " Set the path to libc.so according to the architecture.
1194 let test_bits = system('file ' . GetVimProg())
1195 let test_arch = system('uname -p')
1196 if test_bits =~ '64-bit' && test_arch =~ 'sparc'
1197 let libc = '/usr/lib/sparcv9/libc.so'
1198 elseif test_bits =~ '64-bit' && test_arch =~ 'i386'
1199 let libc = '/usr/lib/amd64/libc.so'
1200 else
1201 let libc = '/usr/lib/libc.so'
1202 endif
1203 else
1204 " Unfortunately skip this test until a good way is found.
1205 return
1206 endif
Bram Moolenaar1ceebb42018-06-19 19:46:06 +02001207 endif
1208
1209 if has('win32')
1210 call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE'))
1211 else
1212 call assert_equal($HOME, libcall(libc, 'getenv', 'HOME'))
1213 endif
1214
1215 " If function returns NULL, libcall() should return an empty string.
1216 call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT'))
1217
1218 " Test libcallnr() with string and integer argument.
1219 call assert_equal(4, libcallnr(libc, 'strlen', 'abcd'))
1220 call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a')))
1221
1222 call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:')
1223 call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:')
1224
1225 call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
1226 call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
1227endfunc
Bram Moolenaard90a1442018-07-15 20:24:31 +02001228
1229sandbox function Fsandbox()
1230 normal ix
1231endfunc
1232
1233func Test_func_sandbox()
1234 sandbox let F = {-> 'hello'}
1235 call assert_equal('hello', F())
1236
1237 sandbox let F = {-> execute("normal ix\<Esc>")}
1238 call assert_fails('call F()', 'E48:')
1239 unlet F
1240
1241 call assert_fails('call Fsandbox()', 'E48:')
1242 delfunc Fsandbox
1243endfunc
Bram Moolenaar9e353b52018-11-04 23:39:38 +01001244
1245func EditAnotherFile()
1246 let word = expand('<cword>')
1247 edit Xfuncrange2
1248endfunc
1249
1250func Test_func_range_with_edit()
1251 " Define a function that edits another buffer, then call it with a range that
1252 " is invalid in that buffer.
1253 call writefile(['just one line'], 'Xfuncrange2')
1254 new
1255 call setline(1, range(10))
1256 write Xfuncrange1
1257 call assert_fails('5,8call EditAnotherFile()', 'E16:')
1258
1259 call delete('Xfuncrange1')
1260 call delete('Xfuncrange2')
1261 bwipe!
1262endfunc
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01001263
1264func Test_func_exists_on_reload()
1265 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists')
1266 call assert_equal(0, exists('*ExistingFunction'))
1267 source Xfuncexists
1268 call assert_equal(1, exists('*ExistingFunction'))
1269 " Redefining a function when reloading a script is OK.
1270 source Xfuncexists
1271 call assert_equal(1, exists('*ExistingFunction'))
1272
1273 " But redefining in another script is not OK.
1274 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2')
1275 call assert_fails('source Xfuncexists2', 'E122:')
1276
1277 delfunc ExistingFunction
1278 call assert_equal(0, exists('*ExistingFunction'))
1279 call writefile([
1280 \ 'func ExistingFunction()', 'echo "yes"', 'endfunc',
1281 \ 'func ExistingFunction()', 'echo "no"', 'endfunc',
1282 \ ], 'Xfuncexists')
1283 call assert_fails('source Xfuncexists', 'E122:')
1284 call assert_equal(1, exists('*ExistingFunction'))
1285
1286 call delete('Xfuncexists2')
1287 call delete('Xfuncexists')
1288 delfunc ExistingFunction
1289endfunc
Bram Moolenaar2e050092019-01-27 15:00:36 +01001290
1291" Test confirm({msg} [, {choices} [, {default} [, {type}]]])
1292func Test_confirm()
1293 if !has('unix') || has('gui_running')
1294 return
1295 endif
1296
1297 call feedkeys('o', 'L')
1298 let a = confirm('Press O to proceed')
1299 call assert_equal(1, a)
1300
1301 call feedkeys('y', 'L')
1302 let a = confirm('Are you sure?', "&Yes\n&No")
1303 call assert_equal(1, a)
1304
1305 call feedkeys('n', 'L')
1306 let a = confirm('Are you sure?', "&Yes\n&No")
1307 call assert_equal(2, a)
1308
1309 " confirm() should return 0 when pressing CTRL-C.
1310 call feedkeys("\<C-c>", 'L')
1311 let a = confirm('Are you sure?', "&Yes\n&No")
1312 call assert_equal(0, a)
1313
1314 " <Esc> requires another character to avoid it being seen as the start of an
1315 " escape sequence. Zero should be harmless.
1316 call feedkeys("\<Esc>0", 'L')
1317 let a = confirm('Are you sure?', "&Yes\n&No")
1318 call assert_equal(0, a)
1319
1320 " Default choice is returned when pressing <CR>.
1321 call feedkeys("\<CR>", 'L')
1322 let a = confirm('Are you sure?', "&Yes\n&No")
1323 call assert_equal(1, a)
1324
1325 call feedkeys("\<CR>", 'L')
1326 let a = confirm('Are you sure?', "&Yes\n&No", 2)
1327 call assert_equal(2, a)
1328
1329 call feedkeys("\<CR>", 'L')
1330 let a = confirm('Are you sure?', "&Yes\n&No", 0)
1331 call assert_equal(0, a)
1332
1333 " Test with the {type} 4th argument
1334 for type in ['Error', 'Question', 'Info', 'Warning', 'Generic']
1335 call feedkeys('y', 'L')
1336 let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type)
1337 call assert_equal(1, a)
1338 endfor
1339
1340 call assert_fails('call confirm([])', 'E730:')
1341 call assert_fails('call confirm("Are you sure?", [])', 'E730:')
1342 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:')
1343 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:')
1344endfunc
Bram Moolenaar39536dd2019-01-29 22:58:21 +01001345
1346func Test_platform_name()
1347 " The system matches at most only one name.
1348 let names = ['amiga', 'beos', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix']
1349 call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)')))
1350
1351 " Is Unix?
1352 call assert_equal(has('beos'), has('beos') && has('unix'))
1353 call assert_equal(has('bsd'), has('bsd') && has('unix'))
1354 call assert_equal(has('hpux'), has('hpux') && has('unix'))
1355 call assert_equal(has('linux'), has('linux') && has('unix'))
1356 call assert_equal(has('mac'), has('mac') && has('unix'))
1357 call assert_equal(has('qnx'), has('qnx') && has('unix'))
1358 call assert_equal(has('sun'), has('sun') && has('unix'))
1359 call assert_equal(has('win32'), has('win32') && !has('unix'))
1360 call assert_equal(has('win32unix'), has('win32unix') && has('unix'))
1361
1362 if has('unix') && executable('uname')
1363 let uname = system('uname')
1364 call assert_equal(uname =~? 'BeOS', has('beos'))
Bram Moolenaara02e3f62019-02-07 21:27:14 +01001365 " GNU userland on BSD kernels (e.g., GNU/kFreeBSD) don't have BSD defined
1366 call assert_equal(uname =~? '\%(GNU/k\w\+\)\@<!BSD\|DragonFly', has('bsd'))
Bram Moolenaar39536dd2019-01-29 22:58:21 +01001367 call assert_equal(uname =~? 'HP-UX', has('hpux'))
1368 call assert_equal(uname =~? 'Linux', has('linux'))
1369 call assert_equal(uname =~? 'Darwin', has('mac'))
1370 call assert_equal(uname =~? 'QNX', has('qnx'))
1371 call assert_equal(uname =~? 'SunOS', has('sun'))
1372 call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix'))
1373 endif
1374endfunc