blob: 1ce5a28f5eb3cbf7391dc0fc5411b32dd1ea3b79 [file] [log] [blame]
Bram Moolenaareca626f2016-12-01 18:47:38 +01001" Test for :mksession, :mkview and :loadview in latin1 encoding
2
3set encoding=latin1
4scriptencoding latin1
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006source check.vim
7CheckFeature mksession
Bram Moolenaareca626f2016-12-01 18:47:38 +01008
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01009source shared.vim
Bram Moolenaar7a39dd72019-06-23 00:50:15 +020010source term_util.vim
Bram Moolenaar4d8bac82018-03-09 21:33:34 +010011
Bram Moolenaar1e15e612019-11-09 17:18:52 +010012" Test for storing global and local argument list in a session file
13" This one must be done first.
14func Test__mksession_arglocal()
15 enew | only
16 n a b c
17 new
18 arglocal
19 mksession! Xtest_mks.out
20
21 %bwipe!
22 %argdelete
23 argglobal
24 source Xtest_mks.out
25 call assert_equal(2, winnr('$'))
26 call assert_equal(2, arglistid(1))
27 call assert_equal(0, arglistid(2))
28
29 %bwipe!
30 %argdelete
31 argglobal
32 call delete('Xtest_mks.out')
33endfunc
34
Bram Moolenaareca626f2016-12-01 18:47:38 +010035func Test_mksession()
36 tabnew
37 let wrap_save = &wrap
38 set sessionoptions=buffers splitbelow fileencoding=latin1
39 call setline(1, [
40 \ 'start:',
41 \ 'no multibyte chAracter',
42 \ ' one leaDing tab',
43 \ ' four leadinG spaces',
44 \ 'two consecutive tabs',
45 \ 'two tabs in one line',
46 \ 'one ä multibyteCharacter',
47 \ 'aä Ä two multiByte characters',
Bram Moolenaar92c1b692018-08-29 21:42:42 +020048 \ 'Aäöü three mulTibyte characters',
49 \ 'short line',
Bram Moolenaareca626f2016-12-01 18:47:38 +010050 \ ])
Bram Moolenaarc9b56b22017-01-29 14:14:09 +010051 let tmpfile = 'Xtemp'
Bram Moolenaareca626f2016-12-01 18:47:38 +010052 exec 'w! ' . tmpfile
53 /^start:
54 set wrap
55 vsplit
56 norm! j16|
57 split
58 norm! j16|
59 split
60 norm! j16|
61 split
62 norm! j8|
63 split
64 norm! j8|
65 split
66 norm! j16|
67 split
68 norm! j16|
69 split
70 norm! j16|
Bram Moolenaar92c1b692018-08-29 21:42:42 +020071 split
72 norm! j$
Bram Moolenaareca626f2016-12-01 18:47:38 +010073 wincmd l
74
75 set nowrap
76 /^start:
77 norm! j16|3zl
78 split
79 norm! j016|3zl
80 split
81 norm! j016|3zl
82 split
83 norm! j08|3zl
84 split
85 norm! j08|3zl
86 split
87 norm! j016|3zl
88 split
89 norm! j016|3zl
90 split
91 norm! j016|3zl
92 split
93 call wincol()
Bram Moolenaarc9b56b22017-01-29 14:14:09 +010094 mksession! Xtest_mks.out
Bram Moolenaar92c1b692018-08-29 21:42:42 +020095 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"')
Bram Moolenaareca626f2016-12-01 18:47:38 +010096 let expected = [
97 \ 'normal! 016|',
98 \ 'normal! 016|',
99 \ 'normal! 016|',
100 \ 'normal! 08|',
101 \ 'normal! 08|',
102 \ 'normal! 016|',
103 \ 'normal! 016|',
104 \ 'normal! 016|',
Bram Moolenaar92c1b692018-08-29 21:42:42 +0200105 \ 'normal! $',
Bram Moolenaareca626f2016-12-01 18:47:38 +0100106 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
107 \ " normal! 016|",
108 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
109 \ " normal! 016|",
110 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
111 \ " normal! 016|",
112 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'",
113 \ " normal! 08|",
114 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'",
115 \ " normal! 08|",
116 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
117 \ " normal! 016|",
118 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
119 \ " normal! 016|",
120 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
121 \ " normal! 016|",
122 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
123 \ " normal! 016|"
124 \ ]
125 call assert_equal(expected, li)
126 tabclose!
127
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100128 call delete('Xtest_mks.out')
Bram Moolenaareca626f2016-12-01 18:47:38 +0100129 call delete(tmpfile)
130 let &wrap = wrap_save
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100131 set sessionoptions&
Bram Moolenaareca626f2016-12-01 18:47:38 +0100132endfunc
133
Bram Moolenaar635bd602021-04-16 19:58:22 +0200134def Test_mksession_skiprtp()
135 mksession! Xtest_mks.out
Bram Moolenaard23b7142021-04-17 21:04:34 +0200136 var found_rtp = 0
137 var found_pp = 0
Bram Moolenaar635bd602021-04-16 19:58:22 +0200138 for line in readfile('Xtest_mks.out')
139 if line =~ 'set runtimepath'
Bram Moolenaard23b7142021-04-17 21:04:34 +0200140 found_rtp += 1
141 endif
142 if line =~ 'set packpath'
143 found_pp += 1
Bram Moolenaar635bd602021-04-16 19:58:22 +0200144 endif
145 endfor
Bram Moolenaard23b7142021-04-17 21:04:34 +0200146 assert_equal(1, found_rtp)
147 assert_equal(1, found_pp)
Bram Moolenaar635bd602021-04-16 19:58:22 +0200148 delete('Xtest_mks.out')
149
150 set sessionoptions+=skiprtp
151 mksession! Xtest_mks.out
Bram Moolenaard23b7142021-04-17 21:04:34 +0200152 var found = 0
Bram Moolenaar635bd602021-04-16 19:58:22 +0200153 for line in readfile('Xtest_mks.out')
Bram Moolenaard23b7142021-04-17 21:04:34 +0200154 if line =~ 'set \(runtimepath\|packpath\)'
Bram Moolenaar635bd602021-04-16 19:58:22 +0200155 found = 1
156 break
157 endif
158 endfor
159 assert_equal(0, found)
160 delete('Xtest_mks.out')
161 set sessionoptions&
162enddef
163
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100164func Test_mksession_winheight()
165 new
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200166 set winheight=10
167 set winminheight=2
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100168 mksession! Xtest_mks.out
169 source Xtest_mks.out
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100170
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100171 call delete('Xtest_mks.out')
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100172endfunc
173
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200174func Test_mksession_large_winheight()
175 set winheight=999
176 mksession! Xtest_mks_winheight.out
177 set winheight&
178 source Xtest_mks_winheight.out
179 call delete('Xtest_mks_winheight.out')
180endfunc
181
Bram Moolenaarb6c2e9a2021-04-30 21:37:51 +0200182func Test_mksession_zero_winheight()
183 set winminheight=0
184 edit SomeFile
185 split
186 wincmd _
187 mksession! Xtest_mks_zero
188 set winminheight&
189 let text = readfile('Xtest_mks_zero')->join()
Dominique Pelle5f8ed742021-05-03 19:08:37 +0200190 call delete('Xtest_mks_zero')
Bram Moolenaarb6c2e9a2021-04-30 21:37:51 +0200191 close
Dominique Pelle5f8ed742021-05-03 19:08:37 +0200192 " check there is no divide by zero
Bram Moolenaarb6c2e9a2021-04-30 21:37:51 +0200193 call assert_notmatch('/ 0[^0-9]', text)
194endfunc
195
Bram Moolenaared18f2c2019-01-24 20:30:52 +0100196func Test_mksession_rtp()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200197 " TODO: fix problem with backslashes on Win32
198 CheckNotMSWindows
199
Bram Moolenaared18f2c2019-01-24 20:30:52 +0100200 new
201 let _rtp=&rtp
202 " Make a real long (invalid) runtimepath value,
203 " that should exceed PATH_MAX (hopefully)
204 let newrtp=&rtp.',~'.repeat('/foobar', 1000)
205 let newrtp.=",".expand("$HOME")."/.vim"
206 let &rtp=newrtp
207
208 " determine expected value
209 let expected=split(&rtp, ',')
210 let expected = map(expected, '"set runtimepath+=".v:val')
211 let expected = ['set runtimepath='] + expected
212 let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")})
213
214 mksession! Xtest_mks.out
215 let &rtp=_rtp
216 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"')
217 call assert_equal(expected, li)
218
219 call delete('Xtest_mks.out')
220endfunc
221
Bram Moolenaar79da5632017-02-01 22:52:44 +0100222func Test_mksession_arglist()
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200223 %argdel
Bram Moolenaar79da5632017-02-01 22:52:44 +0100224 next file1 file2 file3 file4
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200225 new
226 next | next
Bram Moolenaar79da5632017-02-01 22:52:44 +0100227 mksession! Xtest_mks.out
228 source Xtest_mks.out
229 call assert_equal(['file1', 'file2', 'file3', 'file4'], argv())
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200230 call assert_equal(2, argidx())
231 wincmd w
232 call assert_equal(0, argidx())
Bram Moolenaar79da5632017-02-01 22:52:44 +0100233
234 call delete('Xtest_mks.out')
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200235 enew | only
Bram Moolenaar79da5632017-02-01 22:52:44 +0100236 argdel *
237endfunc
238
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200239func Test_mksession_one_buffer_two_windows()
240 edit Xtest1
241 new Xtest2
242 split
243 mksession! Xtest_mks.out
244 let lines = readfile('Xtest_mks.out')
245 let count1 = 0
246 let count2 = 0
247 let count2buf = 0
James Cherti7d428402022-03-14 20:24:51 +0000248 let bufexists = 0
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200249 for line in lines
250 if line =~ 'edit \f*Xtest1$'
251 let count1 += 1
252 endif
253 if line =~ 'edit \f\{-}Xtest2'
254 let count2 += 1
255 endif
256 if line =~ 'buffer \f\{-}Xtest2'
257 let count2buf += 1
258 endif
James Cherti7d428402022-03-14 20:24:51 +0000259 if line =~ 'bufexists(fnamemodify(.*, ":p")'
260 let bufexists += 1
261 endif
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200262 endfor
263 call assert_equal(1, count1, 'Xtest1 count')
264 call assert_equal(2, count2, 'Xtest2 count')
265 call assert_equal(2, count2buf, 'Xtest2 buffer count')
James Cherti7d428402022-03-14 20:24:51 +0000266 call assert_equal(2, bufexists)
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200267
268 close
269 bwipe!
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200270 call delete('Xtest_mks.out')
271endfunc
272
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200273func Test_mksession_lcd_multiple_tabs()
274 tabnew
275 tabnew
Bram Moolenaar81e2ac72018-07-04 22:44:08 +0200276 lcd .
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200277 tabfirst
Bram Moolenaar81e2ac72018-07-04 22:44:08 +0200278 lcd .
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200279 mksession! Xtest_mks.out
280 tabonly
281 source Xtest_mks.out
282 call assert_true(haslocaldir(), 'Tab 1 localdir')
283 tabnext 2
284 call assert_true(!haslocaldir(), 'Tab 2 localdir')
285 tabnext 3
286 call assert_true(haslocaldir(), 'Tab 3 localdir')
287 call delete('Xtest_mks.out')
288endfunc
289
Bram Moolenaar00aa0692019-04-27 20:37:57 +0200290" Test for tabpage-local directory
291func Test_mksession_tcd_multiple_tabs()
292 let save_cwd = getcwd()
293 call mkdir('Xtopdir')
294 cd Xtopdir
295 call mkdir('Xtabdir1')
296 call mkdir('Xtabdir2')
297 call mkdir('Xtabdir3')
298 call mkdir('Xwindir1')
299 call mkdir('Xwindir2')
300 call mkdir('Xwindir3')
301 tcd Xtabdir1
302 botright new
303 wincmd t
304 lcd ../Xwindir1
305 tabnew
306 tcd ../Xtabdir2
307 botright new
308 lcd ../Xwindir2
309 tabnew
310 tcd ../Xtabdir3
311 botright new
312 lcd ../Xwindir3
313 tabfirst
314 1wincmd w
315 mksession! Xtest_mks.out
316 only | tabonly
317 source Xtest_mks.out
318 call assert_equal('Xtabdir1', fnamemodify(getcwd(-1, 1), ':t'))
319 call assert_equal('Xwindir1', fnamemodify(getcwd(1, 1), ':t'))
320 call assert_equal('Xtabdir1', fnamemodify(getcwd(2, 1), ':t'))
321 call assert_equal('Xtabdir2', fnamemodify(getcwd(-1, 2), ':t'))
322 call assert_equal('Xtabdir2', fnamemodify(getcwd(1, 2), ':t'))
323 call assert_equal('Xwindir2', fnamemodify(getcwd(2, 2), ':t'))
324 call assert_equal('Xtabdir3', fnamemodify(getcwd(-1, 3), ':t'))
325 call assert_equal('Xtabdir3', fnamemodify(getcwd(1, 3), ':t'))
326 call assert_equal('Xwindir3', fnamemodify(getcwd(2, 3), ':t'))
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100327 %bwipe
328 call chdir(save_cwd)
Bram Moolenaar00aa0692019-04-27 20:37:57 +0200329 call delete("Xtopdir", "rf")
330endfunc
331
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200332func Test_mksession_blank_tabs()
333 tabnew
334 tabnew
335 tabnew
336 tabnext 3
337 mksession! Xtest_mks.out
338 tabnew
339 tabnew
340 tabnext 2
341 source Xtest_mks.out
342 call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs')
343 call assert_equal(3, tabpagenr(), 'session restore should restore the active tab')
344 call delete('Xtest_mks.out')
345endfunc
346
Bram Moolenaard39e2752019-01-26 20:07:38 +0100347func Test_mksession_buffer_count()
348 set hidden
349
350 " Edit exactly three files in the current session.
351 %bwipe!
352 e Xfoo | tabe Xbar | tabe Xbaz
353 tabdo write
354 mksession! Xtest_mks.out
355
356 " Verify that loading the session does not create additional buffers.
357 %bwipe!
358 source Xtest_mks.out
359 call assert_equal(3, len(getbufinfo()))
360
361 " Clean up.
362 call delete('Xfoo')
363 call delete('Xbar')
364 call delete('Xbaz')
365 call delete('Xtest_mks.out')
366 %bwipe!
367 set hidden&
368endfunc
369
Evgeni Chasnovski26ebf1f2022-01-14 13:19:43 +0000370func Test_mksession_buffer_order()
371 %bwipe!
372 e Xfoo | e Xbar | e Xbaz | e Xqux
373 bufdo write
374 mksession! Xtest_mks.out
375
376 " Verify that loading the session preserves order of buffers
377 %bwipe!
378 source Xtest_mks.out
379
380 let s:buf_info = getbufinfo()
381 call assert_true(s:buf_info[0]['name'] =~# 'Xfoo$')
382 call assert_true(s:buf_info[1]['name'] =~# 'Xbar$')
383 call assert_true(s:buf_info[2]['name'] =~# 'Xbaz$')
384 call assert_true(s:buf_info[3]['name'] =~# 'Xqux$')
385
386 " Clean up.
387 call delete('Xfoo')
388 call delete('Xbar')
389 call delete('Xbaz')
390 call delete('Xqux')
391 call delete('Xtest_mks.out')
392 %bwipe!
393endfunc
394
Bram Moolenaare3c74d22019-01-12 16:29:30 +0100395if has('extra_search')
396
397func Test_mksession_hlsearch()
398 set hlsearch
399 mksession! Xtest_mks.out
400 nohlsearch
401 source Xtest_mks.out
402 call assert_equal(1, v:hlsearch, 'session should restore search highlighting state')
403 nohlsearch
404 mksession! Xtest_mks.out
405 source Xtest_mks.out
406 call assert_equal(0, v:hlsearch, 'session should restore search highlighting state')
407 call delete('Xtest_mks.out')
408endfunc
409
410endif
411
412
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200413func Test_mksession_blank_windows()
414 split
415 split
416 split
417 3 wincmd w
418 mksession! Xtest_mks.out
419 split
420 split
421 2 wincmd w
422 source Xtest_mks.out
423 call assert_equal(4, winnr('$'), 'session restore should restore number of windows')
424 call assert_equal(3, winnr(), 'session restore should restore the active window')
425 call delete('Xtest_mks.out')
426endfunc
427
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100428func Test_mksession_terminal_shell()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200429 CheckFeature terminal
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100430 CheckFeature quickfix
431
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100432 terminal
433 mksession! Xtest_mks.out
434 let lines = readfile('Xtest_mks.out')
435 let term_cmd = ''
436 for line in lines
437 if line =~ '^terminal'
438 let term_cmd = line
439 elseif line =~ 'badd.*' . &shell
440 call assert_report('unexpected shell line: ' . line)
441 endif
442 endfor
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +0100443 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd)
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100444
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200445 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100446 call delete('Xtest_mks.out')
447endfunc
448
449func Test_mksession_terminal_no_restore_cmdarg()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200450 CheckFeature terminal
451
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100452 terminal ++norestore
453 mksession! Xtest_mks.out
454 let lines = readfile('Xtest_mks.out')
455 let term_cmd = ''
456 for line in lines
457 if line =~ '^terminal'
Bram Moolenaarac665c22020-12-08 20:39:15 +0100458 call assert_report('session must not restore terminal')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100459 endif
460 endfor
461
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200462 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100463 call delete('Xtest_mks.out')
464endfunc
465
466func Test_mksession_terminal_no_restore_funcarg()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200467 CheckFeature terminal
468
Bram Moolenaar3a6aadb2021-04-04 15:28:59 +0200469 let buf = Run_shell_in_terminal({'norestore': 1})
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100470 mksession! Xtest_mks.out
471 let lines = readfile('Xtest_mks.out')
472 let term_cmd = ''
473 for line in lines
474 if line =~ '^terminal'
Bram Moolenaarac665c22020-12-08 20:39:15 +0100475 call assert_report('session must not restore terminal')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100476 endif
477 endfor
478
Bram Moolenaar3a6aadb2021-04-04 15:28:59 +0200479 call StopShellInTerminal(buf)
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100480 call delete('Xtest_mks.out')
481endfunc
482
483func Test_mksession_terminal_no_restore_func()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200484 CheckFeature terminal
485
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100486 terminal
487 call term_setrestore(bufnr('%'), 'NONE')
488 mksession! Xtest_mks.out
489 let lines = readfile('Xtest_mks.out')
490 let term_cmd = ''
491 for line in lines
492 if line =~ '^terminal'
Bram Moolenaarac665c22020-12-08 20:39:15 +0100493 call assert_report('session must not restore terminal')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100494 endif
495 endfor
496
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200497 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100498 call delete('Xtest_mks.out')
499endfunc
500
501func Test_mksession_terminal_no_ssop()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200502 CheckFeature terminal
503
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100504 terminal
505 set sessionoptions-=terminal
506 mksession! Xtest_mks.out
507 let lines = readfile('Xtest_mks.out')
508 let term_cmd = ''
509 for line in lines
510 if line =~ '^terminal'
Bram Moolenaarac665c22020-12-08 20:39:15 +0100511 call assert_report('session must not restore terminal')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100512 endif
513 endfor
514
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200515 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100516 call delete('Xtest_mks.out')
517 set sessionoptions&
518endfunc
519
520func Test_mksession_terminal_restore_other()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200521 CheckFeature terminal
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100522 CheckFeature quickfix
523
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100524 terminal
Bram Moolenaar7ee80f72019-09-08 20:55:06 +0200525 eval bufnr('%')->term_setrestore('other')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100526 mksession! Xtest_mks.out
527 let lines = readfile('Xtest_mks.out')
528 let term_cmd = ''
529 for line in lines
530 if line =~ '^terminal'
531 let term_cmd = line
532 endif
533 endfor
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +0100534 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd)
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100535
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200536 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100537 call delete('Xtest_mks.out')
538endfunc
539
Bram Moolenaar0e655112020-09-11 20:36:36 +0200540func Test_mksession_terminal_shared_windows()
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200541 CheckFeature terminal
542
Bram Moolenaar0e655112020-09-11 20:36:36 +0200543 terminal
544 let term_buf = bufnr()
545 new
546 execute "buffer" term_buf
547 mksession! Xtest_mks.out
548
549 let lines = readfile('Xtest_mks.out')
550 let found_creation = 0
551 let found_use = 0
552
553 for line in lines
554 if line =~ '^terminal'
555 let found_creation = 1
556 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+', line)
557 elseif line =~ "^execute 'buffer ' . s:term_buf_" . term_buf . "$"
558 let found_use = 1
559 endif
560 endfor
561
562 call assert_true(found_creation && found_use)
563
564 call StopShellInTerminal(term_buf)
565 call delete('Xtest_mks.out')
566endfunc
567
Bram Moolenaarc2c82052020-09-11 22:10:22 +0200568func Test_mkview_terminal_windows()
569 CheckFeature terminal
570
571 " create two window on the same terminal to check this is handled OK
572 terminal
573 let term_buf = bufnr()
574 exe 'sbuf ' .. term_buf
575 mkview! Xtestview
576
577 call StopShellInTerminal(term_buf)
578 call delete('Xtestview')
579endfunc
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200580
Bram Moolenaarf9547eb2021-02-01 19:24:55 +0100581func Test_mkview_open_folds()
582 enew!
583
584 call append(0, ['a', 'b', 'c'])
585 1,3fold
Bram Moolenaarf9547eb2021-02-01 19:24:55 +0100586 write! Xtestfile
587
James McCoyc829faa2022-06-19 17:16:18 +0100588 call assert_notequal(-1, foldclosed(1))
589 call assert_notequal(-1, foldclosed(2))
590 call assert_notequal(-1, foldclosed(3))
591
592 " Save the view with folds closed
593 mkview! Xtestview
594
595 " zR affects 'foldlevel', make sure the option is applied after the folds
596 " have been recreated.
597 " Open folds to ensure they get closed when restoring the view
598 normal zR
599
Bram Moolenaarf9547eb2021-02-01 19:24:55 +0100600 call assert_equal(-1, foldclosed(1))
601 call assert_equal(-1, foldclosed(2))
602 call assert_equal(-1, foldclosed(3))
603
Bram Moolenaarf9547eb2021-02-01 19:24:55 +0100604 source Xtestview
605
James McCoyc829faa2022-06-19 17:16:18 +0100606 call assert_notequal(-1, foldclosed(1))
607 call assert_notequal(-1, foldclosed(2))
608 call assert_notequal(-1, foldclosed(3))
Bram Moolenaarf9547eb2021-02-01 19:24:55 +0100609
610 call delete('Xtestview')
611 call delete('Xtestfile')
612 %bwipe
613endfunc
614
Bram Moolenaar139348f2021-02-05 21:55:53 +0100615func Test_mkview_no_balt()
616 edit Xtestfile1
617 edit Xtestfile2
618
619 mkview! Xtestview
620 bdelete Xtestfile1
621
622 source Xtestview
623 call assert_equal(0, buflisted('Xtestfile1'))
624
625 call delete('Xtestview')
626 %bwipe
627endfunc
628
Bram Moolenaar0756f752021-03-13 13:52:33 +0100629func Test_mksession_no_balt()
630 edit Xtestfile1
631 edit Xtestfile2
632
633 bdelete Xtestfile1
634 mksession! Xtestview
635
636 source Xtestview
637 call assert_equal(0, buflisted('Xtestfile1'))
638
639 call delete('Xtestview')
640 %bwipe
641endfunc
642
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200643" Test :mkview with a file argument.
644func Test_mkview_file()
645 " Create a view with line number and a fold.
646 help :mkview
647 set number
Bram Moolenaar2bf4fe02018-08-30 14:04:25 +0200648 norm! V}zf0
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200649 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200650 let linefoldclosed1 = foldclosed('.')
651 mkview! Xview
652 set nonumber
653 norm! zrj
654 " We can close the help window, as mkview with a file name should
655 " generate a command to edit the file.
656 helpclose
657
658 source Xview
659 call assert_equal(1, &number)
660 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200661 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200662 call assert_equal(linefoldclosed1, foldclosed('.'))
663
664 " Creating a view again with the same file name should fail (file
665 " already exists). But with a !, the previous view should be
666 " overwritten without error.
667 help :loadview
668 call assert_fails('mkview Xview', 'E189:')
669 call assert_match('\*:loadview\*$', getline('.'))
670 mkview! Xview
671 call assert_match('\*:loadview\*$', getline('.'))
672
673 call delete('Xview')
674 bwipe
675endfunc
676
677" Test :mkview and :loadview with a custom 'viewdir'.
678func Test_mkview_loadview_with_viewdir()
679 set viewdir=Xviewdir
680
681 help :mkview
682 set number
683 norm! V}zf
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200684 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200685 let linefoldclosed1 = foldclosed('.')
686 mkview 1
687 set nonumber
688 norm! zrj
689
690 loadview 1
691
692 " The directory Xviewdir/ should have been created and the view
693 " should be stored in that directory.
694 call assert_equal('Xviewdir/' .
695 \ substitute(
696 \ substitute(
697 \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim',
698 \ glob('Xviewdir/*'))
699 call assert_equal(1, &number)
700 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200701 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200702 call assert_equal(linefoldclosed1, foldclosed('.'))
703
704 call delete('Xviewdir', 'rf')
705 set viewdir&
706 helpclose
707endfunc
708
709func Test_mkview_no_file_name()
710 new
711 " :mkview or :mkview {nr} should fail in a unnamed buffer.
712 call assert_fails('mkview', 'E32:')
713 call assert_fails('mkview 1', 'E32:')
714
715 " :mkview {file} should succeed in a unnamed buffer.
716 mkview Xview
717 help
718 source Xview
719 call assert_equal('', bufname('%'))
720
721 call delete('Xview')
722 %bwipe
723endfunc
Bram Moolenaar79da5632017-02-01 22:52:44 +0100724
Bram Moolenaar3482be62020-11-27 11:00:38 +0100725func Test_mkview_loadview_jumplist()
726 set viewdir=Xviewdir
727 au BufWinLeave * silent mkview
728 au BufWinEnter * silent loadview
729
730 edit Xfile1
731 call setline(1, ['a', 'bbbbbbb', 'c'])
732 normal j3l
733 call assert_equal([2, 4], getcurpos()[1:2])
734 write
735
736 edit Xfile2
737 call setline(1, ['d', 'eeeeeee', 'f'])
738 normal j5l
739 call assert_equal([2, 6], getcurpos()[1:2])
740 write
741
742 edit Xfile3
743 call setline(1, ['g', 'h', 'iiiii'])
744 normal jj3l
745 call assert_equal([3, 4], getcurpos()[1:2])
746 write
747
748 edit Xfile1
749 call assert_equal([2, 4], getcurpos()[1:2])
750 edit Xfile2
751 call assert_equal([2, 6], getcurpos()[1:2])
752 edit Xfile3
753 call assert_equal([3, 4], getcurpos()[1:2])
754
755 exe "normal \<C-O>"
756 call assert_equal('Xfile2', expand('%'))
757 call assert_equal([2, 6], getcurpos()[1:2])
758 exe "normal \<C-O>"
759 call assert_equal('Xfile1', expand('%'))
760 call assert_equal([2, 4], getcurpos()[1:2])
761
762 au! BufWinLeave
763 au! BufWinEnter
764 bwipe!
765 call delete('Xviewdir', 'rf')
766 call delete('Xfile1')
767 call delete('Xfile2')
768 call delete('Xfile3')
769 set viewdir&
770endfunc
771
Bram Moolenaar555de4e2019-01-21 23:03:49 +0100772" A clean session (one empty buffer, one window, and one tab) should not
773" set any error messages when sourced because no commands should fail.
774func Test_mksession_no_errmsg()
775 let v:errmsg = ''
776 %bwipe!
777 mksession! Xtest_mks.out
778 source Xtest_mks.out
779 call assert_equal('', v:errmsg)
780 call delete('Xtest_mks.out')
781endfunc
782
Bram Moolenaarad36a352019-01-24 13:34:42 +0100783func Test_mksession_quote_in_filename()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200784 " only Unix can handle this weird filename
785 CheckUnix
786
Bram Moolenaarad36a352019-01-24 13:34:42 +0100787 let v:errmsg = ''
788 %bwipe!
789 split another
790 split x'y\"z
791 mksession! Xtest_mks_quoted.out
792 %bwipe!
793 source Xtest_mks_quoted.out
794 call assert_true(bufexists("x'y\"z"))
795
796 %bwipe!
797 call delete('Xtest_mks_quoted.out')
798endfunc
799
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200800" Test for storing global variables in a session file
801func Test_mksession_globals()
802 set sessionoptions+=globals
803
804 " create different global variables
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200805 let g:Global_string = "Sun is shining\r\n"
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200806 let g:Global_count = 100
807 let g:Global_pi = 3.14
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200808 let g:Global_neg_float = -2.68
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200809
810 mksession! Xtest_mks.out
811
812 unlet g:Global_string
813 unlet g:Global_count
814 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200815 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200816
817 source Xtest_mks.out
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200818 call assert_equal("Sun is shining\r\n", g:Global_string)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200819 call assert_equal(100, g:Global_count)
820 call assert_equal(3.14, g:Global_pi)
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200821 call assert_equal(-2.68, g:Global_neg_float)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200822
823 unlet g:Global_string
824 unlet g:Global_count
825 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200826 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200827 call delete('Xtest_mks.out')
828 set sessionoptions&
829endfunc
830
831" Test for changing backslash to forward slash in filenames
832func Test_mksession_slash()
Bram Moolenaar37ac4a52019-09-28 19:29:04 +0200833 if exists('+shellslash')
834 throw 'Skipped: cannot use backslash in file name'
835 endif
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200836 enew
837 %bwipe!
838 e a\\b\\c
839 mksession! Xtest_mks1.out
840 set sessionoptions+=slash
841 mksession! Xtest_mks2.out
842
843 %bwipe!
844 source Xtest_mks1.out
845 call assert_equal('a\b\c', bufname(''))
846 %bwipe!
847 source Xtest_mks2.out
848 call assert_equal('a/b/c', bufname(''))
849
850 %bwipe!
851 call delete('Xtest_mks1.out')
852 call delete('Xtest_mks2.out')
853 set sessionoptions&
854endfunc
855
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200856" Test for changing directory to the session file directory
857func Test_mksession_sesdir()
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100858 let save_cwd = getcwd()
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200859 call mkdir('Xproj')
860 mksession! Xproj/Xtest_mks1.out
861 set sessionoptions-=curdir
862 set sessionoptions+=sesdir
863 mksession! Xproj/Xtest_mks2.out
864
865 source Xproj/Xtest_mks1.out
866 call assert_equal('testdir', fnamemodify(getcwd(), ':t'))
867 source Xproj/Xtest_mks2.out
868 call assert_equal('Xproj', fnamemodify(getcwd(), ':t'))
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100869 call chdir(save_cwd)
870 %bwipe
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200871
872 set sessionoptions&
873 call delete('Xproj', 'rf')
874endfunc
875
LemonBoyd7c95642022-04-30 16:10:27 +0100876" Test for saving and restoring the tab-local working directory when there is
877" only a single tab and 'tabpages' is not in 'sessionoptions'.
878func Test_mksession_tcd_single_tabs()
879 only | tabonly
880
881 let save_cwd = getcwd()
882 set sessionoptions-=tabpages
883 set sessionoptions+=curdir
884 call mkdir('Xtopdir1')
885 call mkdir('Xtopdir2')
886
887 " There are two tab pages, the current one has local cwd set to 'Xtopdir2'.
888 exec 'tcd ' .. save_cwd .. '/Xtopdir1'
889 tabnew
890 exec 'tcd ' .. save_cwd .. '/Xtopdir2'
891 mksession! Xtest_tcd_single
892
893 source Xtest_tcd_single
894 call assert_equal(2, haslocaldir())
895 call assert_equal('Xtopdir2', fnamemodify(getcwd(-1, 0), ':t'))
896 %bwipe
897
898 set sessionoptions&
899 call chdir(save_cwd)
900 call delete('Xtopdir1', 'rf')
901 call delete('Xtopdir2', 'rf')
902endfunc
903
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200904" Test for storing the 'lines' and 'columns' settings
905func Test_mksession_resize()
906 mksession! Xtest_mks1.out
907 set sessionoptions+=resize
908 mksession! Xtest_mks2.out
909
910 let lines = readfile('Xtest_mks1.out')
911 let found_resize = v:false
912 for line in lines
913 if line =~ '^set lines='
914 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200915 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200916 endif
917 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200918 call assert_false(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200919 let lines = readfile('Xtest_mks2.out')
920 let found_resize = v:false
921 for line in lines
922 if line =~ '^set lines='
923 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200924 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200925 endif
926 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200927 call assert_true(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200928
929 call delete('Xtest_mks1.out')
930 call delete('Xtest_mks2.out')
931 set sessionoptions&
932endfunc
933
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200934" Test for mksession with a named scratch buffer
935func Test_mksession_scratch()
936 enew | only
937 file Xscratch
938 set buftype=nofile
939 mksession! Xtest_mks.out
940 %bwipe
941 source Xtest_mks.out
942 call assert_equal('Xscratch', bufname(''))
943 call assert_equal('nofile', &buftype)
944 %bwipe
945 call delete('Xtest_mks.out')
946endfunc
947
948" Test for mksession with fold options
949func Test_mksession_foldopt()
950 set sessionoptions-=options
951 set sessionoptions+=folds
952 new
953 setlocal foldenable
954 setlocal foldmethod=expr
955 setlocal foldmarker=<<<,>>>
956 setlocal foldignore=%
957 setlocal foldlevel=2
958 setlocal foldminlines=10
959 setlocal foldnestmax=15
960 mksession! Xtest_mks.out
961 close
962 %bwipe
963
964 source Xtest_mks.out
965 call assert_true(&foldenable)
966 call assert_equal('expr', &foldmethod)
967 call assert_equal('<<<,>>>', &foldmarker)
968 call assert_equal('%', &foldignore)
969 call assert_equal(2, &foldlevel)
970 call assert_equal(10, &foldminlines)
971 call assert_equal(15, &foldnestmax)
972
973 close
974 %bwipe
975 set sessionoptions&
976endfunc
977
matveyt8e7d9db2022-01-05 14:01:30 +0000978" Test for mksession with "help" but not "options" in 'sessionoptions'
979func Test_mksession_help_noopt()
980 set sessionoptions-=options
981 set sessionoptions+=help
982 help
983 let fname = expand('%')
984 mksession! Xtest_mks.out
985 bwipe
986
987 source Xtest_mks.out
988 call assert_equal('help', &buftype)
989 call assert_equal('help', &filetype)
990 call assert_equal(fname, expand('%'))
991 call assert_false(&modifiable)
992 call assert_true(&readonly)
993
994 helpclose
995 help index
996 let fname = expand('%')
997 mksession! Xtest_mks.out
998 bwipe
999
1000 source Xtest_mks.out
1001 call assert_equal('help', &buftype)
1002 call assert_equal(fname, expand('%'))
1003
1004 call delete('Xtest_mks.out')
1005 set sessionoptions&
1006endfunc
1007
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001008" Test for mksession with window position
1009func Test_mksession_winpos()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001010 " Only applicable in GUI Vim
1011 CheckGui
1012
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001013 set sessionoptions+=winpos
1014 mksession! Xtest_mks.out
1015 let found_winpos = v:false
1016 let lines = readfile('Xtest_mks.out')
1017 for line in lines
1018 if line =~ '^winpos '
1019 let found_winpos = v:true
1020 break
1021 endif
1022 endfor
1023 call assert_true(found_winpos)
1024 call delete('Xtest_mks.out')
1025 set sessionoptions&
1026endfunc
1027
Bram Moolenaar0995c812021-04-17 18:38:54 +02001028" Test for mksession without options restores winminheight
1029func Test_mksession_winminheight()
1030 set sessionoptions-=options
1031 split
1032 mksession! Xtest_mks.out
1033 let found_restore = 0
1034 let lines = readfile('Xtest_mks.out')
1035 for line in lines
1036 if line =~ '= s:save_winmin\(width\|height\)'
1037 let found_restore += 1
1038 endif
1039 endfor
1040 call assert_equal(2, found_restore)
1041 call delete('Xtest_mks.out')
1042 close
1043 set sessionoptions&
1044endfunc
1045
James Chertifd012802022-03-29 12:02:57 +01001046" Test for mksession with and without options restores shortmess
1047func Test_mksession_shortmess()
1048 " Without options
1049 set sessionoptions-=options
1050 split
1051 mksession! Xtest_mks.out
1052 let found_save = 0
1053 let found_restore = 0
1054 let lines = readfile('Xtest_mks.out')
1055 for line in lines
1056 let line = trim(line)
1057
1058 if line ==# 'let s:shortmess_save = &shortmess'
1059 let found_save += 1
1060 endif
1061
1062 if found_save !=# 0 && line ==# 'let &shortmess = s:shortmess_save'
1063 let found_restore += 1
1064 endif
1065 endfor
1066 call assert_equal(1, found_save)
1067 call assert_equal(1, found_restore)
1068 call delete('Xtest_mks.out')
1069 close
1070 set sessionoptions&
1071
1072 " With options
1073 set sessionoptions+=options
1074 split
1075 mksession! Xtest_mks.out
1076 let found_restore = 0
1077 let lines = readfile('Xtest_mks.out')
1078 for line in lines
1079 if line =~# 's:shortmess_save'
1080 let found_restore += 1
1081 endif
1082 endfor
1083 call assert_equal(0, found_restore)
1084 call delete('Xtest_mks.out')
1085 close
1086 set sessionoptions&
1087endfunc
1088
Bram Moolenaaraaadb5b2022-05-18 22:07:47 +01001089" Test that when Vim loading session has 'A' in 'shortmess' it does not
1090" complain about an existing swapfile.
1091func Test_mksession_shortmess_with_A()
1092 edit Xtestfile
1093 write
1094 let fname = swapname('%')
1095 let cont = readblob(fname)
1096 set sessionoptions-=options
1097 mksession Xtestsession
1098 bwipe!
1099
1100 " Recreate the swap file to pretend the file is being edited
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001101 call writefile(cont, fname, 'D')
Bram Moolenaaraaadb5b2022-05-18 22:07:47 +01001102 set shortmess+=A
1103 source Xtestsession
1104
1105 set shortmess&
1106 set sessionoptions&
1107 call delete('Xtestsession')
Bram Moolenaaraaadb5b2022-05-18 22:07:47 +01001108endfunc
1109
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001110" Test for mksession with 'compatible' option
1111func Test_mksession_compatible()
1112 mksession! Xtest_mks1.out
1113 set compatible
1114 mksession! Xtest_mks2.out
1115 set nocp
1116
1117 let test_success = v:false
1118 let lines = readfile('Xtest_mks1.out')
1119 for line in lines
1120 if line =~ '^if &cp | set nocp | endif'
1121 let test_success = v:true
1122 break
1123 endif
1124 endfor
1125 call assert_true(test_success)
1126
1127 let test_success = v:false
1128 let lines = readfile('Xtest_mks2.out')
1129 for line in lines
1130 if line =~ '^if !&cp | set cp | endif'
1131 let test_success = v:true
1132 break
1133 endif
1134 endfor
1135 call assert_true(test_success)
1136
1137 call delete('Xtest_mks1.out')
1138 call delete('Xtest_mks2.out')
1139 set compatible&
1140 set sessionoptions&
1141endfunc
1142
Bram Moolenaar87500262019-08-01 23:05:49 +02001143func s:ClearMappings()
1144 mapclear
1145 omapclear
1146 mapclear!
1147 lmapclear
1148 tmapclear
1149endfunc
1150
1151func Test_mkvimrc()
1152 let entries = [
1153 \ ['', 'nothing', '<Nop>'],
1154 \ ['n', 'normal', 'NORMAL'],
1155 \ ['v', 'visual', 'VISUAL'],
1156 \ ['s', 'select', 'SELECT'],
1157 \ ['x', 'visualonly', 'VISUALONLY'],
1158 \ ['o', 'operator', 'OPERATOR'],
1159 \ ['i', 'insert', 'INSERT'],
1160 \ ['l', 'lang', 'LANG'],
1161 \ ['c', 'command', 'COMMAND'],
1162 \ ['t', 'terminal', 'TERMINAL'],
1163 \ ]
1164 for entry in entries
1165 exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2]
1166 endfor
1167
1168 mkvimrc Xtestvimrc
1169
1170 call s:ClearMappings()
1171 for entry in entries
1172 call assert_equal('', maparg(entry[1], entry[0]))
1173 endfor
1174
1175 source Xtestvimrc
1176
1177 for entry in entries
1178 call assert_equal(entry[2], maparg(entry[1], entry[0]))
1179 endfor
1180
1181 call s:ClearMappings()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001182
1183 " the 'pastetoggle', 'wildchar' and 'wildcharm' option values should be
1184 " stored as key names in the vimrc file
1185 set pastetoggle=<F5>
1186 set wildchar=<F6>
1187 set wildcharm=<F7>
1188 call assert_fails('mkvimrc Xtestvimrc')
1189 mkvimrc! Xtestvimrc
1190 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=<F5>'))
1191 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildchar=<F6>'))
1192 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildcharm=<F7>'))
1193 set pastetoggle& wildchar& wildcharm&
1194
Bram Moolenaar87500262019-08-01 23:05:49 +02001195 call delete('Xtestvimrc')
1196endfunc
1197
Bram Moolenaar38890832020-11-01 17:40:54 +01001198func Test_scrolloff()
1199 set sessionoptions+=localoptions
1200 setlocal so=1 siso=1
1201 mksession! Xtest_mks.out
1202 setlocal so=-1 siso=-1
1203 source Xtest_mks.out
1204 call assert_equal(1, &l:so)
1205 call assert_equal(1, &l:siso)
1206 call delete('Xtest_mks.out')
1207 setlocal so& siso&
1208 set sessionoptions&
1209endfunc
1210
Bram Moolenaar3482be62020-11-27 11:00:38 +01001211func Test_altfile()
1212 edit Xone
1213 split Xtwo
1214 edit Xtwoalt
1215 edit #
1216 wincmd w
1217 edit Xonealt
1218 edit #
1219 mksession! Xtest_altfile
1220 only
1221 bwipe Xonealt
1222 bwipe Xtwoalt
1223 bwipe!
1224 source Xtest_altfile
1225 call assert_equal('Xone', bufname())
1226 call assert_equal('Xonealt', bufname('#'))
1227 wincmd w
1228 call assert_equal('Xtwo', bufname())
1229 call assert_equal('Xtwoalt', bufname('#'))
1230 only
1231 bwipe!
Bram Moolenaarac665c22020-12-08 20:39:15 +01001232 call delete('Xtest_altfile')
Bram Moolenaar3482be62020-11-27 11:00:38 +01001233endfunc
1234
Bram Moolenaar5c504f62021-04-01 13:39:51 +02001235" Test for creating views with manual folds
1236func Test_mkview_manual_fold()
Bram Moolenaarb152b6a2022-09-29 21:37:33 +01001237 call writefile(range(1,10), 'Xmkvfile', 'D')
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001238 new Xmkvfile
Bram Moolenaar5c504f62021-04-01 13:39:51 +02001239 " create recursive folds
1240 5,6fold
1241 4,7fold
1242 mkview Xview
1243 normal zE
1244 source Xview
1245 call assert_equal([-1, 4, 4, 4, 4, -1], [foldclosed(3), foldclosed(4),
1246 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
1247 " open one level of fold
1248 4foldopen
1249 mkview! Xview
1250 normal zE
1251 source Xview
1252 call assert_equal([-1, -1, 5, 5, -1, -1], [foldclosed(3), foldclosed(4),
1253 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
1254 " open all the folds
1255 %foldopen!
1256 mkview! Xview
1257 normal zE
1258 source Xview
1259 call assert_equal([-1, -1, -1, -1, -1, -1], [foldclosed(3), foldclosed(4),
1260 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
Bram Moolenaar5c504f62021-04-01 13:39:51 +02001261 call delete('Xview')
1262 bw!
1263endfunc
1264
Bram Moolenaareca626f2016-12-01 18:47:38 +01001265" vim: shiftwidth=2 sts=2 expandtab