blob: 2e368df8d9cbe3db28432938b62f67d5f7f86ee3 [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
586 " zR affects 'foldlevel', make sure the option is applied after the folds
587 " have been recreated.
588 normal zR
589 write! Xtestfile
590
591 call assert_equal(-1, foldclosed(1))
592 call assert_equal(-1, foldclosed(2))
593 call assert_equal(-1, foldclosed(3))
594
595 mkview! Xtestview
596 source Xtestview
597
598 call assert_equal(-1, foldclosed(1))
599 call assert_equal(-1, foldclosed(2))
600 call assert_equal(-1, foldclosed(3))
601
602 call delete('Xtestview')
603 call delete('Xtestfile')
604 %bwipe
605endfunc
606
Bram Moolenaar139348f2021-02-05 21:55:53 +0100607func Test_mkview_no_balt()
608 edit Xtestfile1
609 edit Xtestfile2
610
611 mkview! Xtestview
612 bdelete Xtestfile1
613
614 source Xtestview
615 call assert_equal(0, buflisted('Xtestfile1'))
616
617 call delete('Xtestview')
618 %bwipe
619endfunc
620
Bram Moolenaar0756f752021-03-13 13:52:33 +0100621func Test_mksession_no_balt()
622 edit Xtestfile1
623 edit Xtestfile2
624
625 bdelete Xtestfile1
626 mksession! Xtestview
627
628 source Xtestview
629 call assert_equal(0, buflisted('Xtestfile1'))
630
631 call delete('Xtestview')
632 %bwipe
633endfunc
634
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200635" Test :mkview with a file argument.
636func Test_mkview_file()
637 " Create a view with line number and a fold.
638 help :mkview
639 set number
Bram Moolenaar2bf4fe02018-08-30 14:04:25 +0200640 norm! V}zf0
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200641 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200642 let linefoldclosed1 = foldclosed('.')
643 mkview! Xview
644 set nonumber
645 norm! zrj
646 " We can close the help window, as mkview with a file name should
647 " generate a command to edit the file.
648 helpclose
649
650 source Xview
651 call assert_equal(1, &number)
652 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200653 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200654 call assert_equal(linefoldclosed1, foldclosed('.'))
655
656 " Creating a view again with the same file name should fail (file
657 " already exists). But with a !, the previous view should be
658 " overwritten without error.
659 help :loadview
660 call assert_fails('mkview Xview', 'E189:')
661 call assert_match('\*:loadview\*$', getline('.'))
662 mkview! Xview
663 call assert_match('\*:loadview\*$', getline('.'))
664
665 call delete('Xview')
666 bwipe
667endfunc
668
669" Test :mkview and :loadview with a custom 'viewdir'.
670func Test_mkview_loadview_with_viewdir()
671 set viewdir=Xviewdir
672
673 help :mkview
674 set number
675 norm! V}zf
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200676 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200677 let linefoldclosed1 = foldclosed('.')
678 mkview 1
679 set nonumber
680 norm! zrj
681
682 loadview 1
683
684 " The directory Xviewdir/ should have been created and the view
685 " should be stored in that directory.
686 call assert_equal('Xviewdir/' .
687 \ substitute(
688 \ substitute(
689 \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim',
690 \ glob('Xviewdir/*'))
691 call assert_equal(1, &number)
692 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200693 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200694 call assert_equal(linefoldclosed1, foldclosed('.'))
695
696 call delete('Xviewdir', 'rf')
697 set viewdir&
698 helpclose
699endfunc
700
701func Test_mkview_no_file_name()
702 new
703 " :mkview or :mkview {nr} should fail in a unnamed buffer.
704 call assert_fails('mkview', 'E32:')
705 call assert_fails('mkview 1', 'E32:')
706
707 " :mkview {file} should succeed in a unnamed buffer.
708 mkview Xview
709 help
710 source Xview
711 call assert_equal('', bufname('%'))
712
713 call delete('Xview')
714 %bwipe
715endfunc
Bram Moolenaar79da5632017-02-01 22:52:44 +0100716
Bram Moolenaar3482be62020-11-27 11:00:38 +0100717func Test_mkview_loadview_jumplist()
718 set viewdir=Xviewdir
719 au BufWinLeave * silent mkview
720 au BufWinEnter * silent loadview
721
722 edit Xfile1
723 call setline(1, ['a', 'bbbbbbb', 'c'])
724 normal j3l
725 call assert_equal([2, 4], getcurpos()[1:2])
726 write
727
728 edit Xfile2
729 call setline(1, ['d', 'eeeeeee', 'f'])
730 normal j5l
731 call assert_equal([2, 6], getcurpos()[1:2])
732 write
733
734 edit Xfile3
735 call setline(1, ['g', 'h', 'iiiii'])
736 normal jj3l
737 call assert_equal([3, 4], getcurpos()[1:2])
738 write
739
740 edit Xfile1
741 call assert_equal([2, 4], getcurpos()[1:2])
742 edit Xfile2
743 call assert_equal([2, 6], getcurpos()[1:2])
744 edit Xfile3
745 call assert_equal([3, 4], getcurpos()[1:2])
746
747 exe "normal \<C-O>"
748 call assert_equal('Xfile2', expand('%'))
749 call assert_equal([2, 6], getcurpos()[1:2])
750 exe "normal \<C-O>"
751 call assert_equal('Xfile1', expand('%'))
752 call assert_equal([2, 4], getcurpos()[1:2])
753
754 au! BufWinLeave
755 au! BufWinEnter
756 bwipe!
757 call delete('Xviewdir', 'rf')
758 call delete('Xfile1')
759 call delete('Xfile2')
760 call delete('Xfile3')
761 set viewdir&
762endfunc
763
Bram Moolenaar555de4e2019-01-21 23:03:49 +0100764" A clean session (one empty buffer, one window, and one tab) should not
765" set any error messages when sourced because no commands should fail.
766func Test_mksession_no_errmsg()
767 let v:errmsg = ''
768 %bwipe!
769 mksession! Xtest_mks.out
770 source Xtest_mks.out
771 call assert_equal('', v:errmsg)
772 call delete('Xtest_mks.out')
773endfunc
774
Bram Moolenaarad36a352019-01-24 13:34:42 +0100775func Test_mksession_quote_in_filename()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200776 " only Unix can handle this weird filename
777 CheckUnix
778
Bram Moolenaarad36a352019-01-24 13:34:42 +0100779 let v:errmsg = ''
780 %bwipe!
781 split another
782 split x'y\"z
783 mksession! Xtest_mks_quoted.out
784 %bwipe!
785 source Xtest_mks_quoted.out
786 call assert_true(bufexists("x'y\"z"))
787
788 %bwipe!
789 call delete('Xtest_mks_quoted.out')
790endfunc
791
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200792" Test for storing global variables in a session file
793func Test_mksession_globals()
794 set sessionoptions+=globals
795
796 " create different global variables
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200797 let g:Global_string = "Sun is shining\r\n"
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200798 let g:Global_count = 100
799 let g:Global_pi = 3.14
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200800 let g:Global_neg_float = -2.68
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200801
802 mksession! Xtest_mks.out
803
804 unlet g:Global_string
805 unlet g:Global_count
806 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200807 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200808
809 source Xtest_mks.out
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200810 call assert_equal("Sun is shining\r\n", g:Global_string)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200811 call assert_equal(100, g:Global_count)
812 call assert_equal(3.14, g:Global_pi)
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200813 call assert_equal(-2.68, g:Global_neg_float)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200814
815 unlet g:Global_string
816 unlet g:Global_count
817 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200818 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200819 call delete('Xtest_mks.out')
820 set sessionoptions&
821endfunc
822
823" Test for changing backslash to forward slash in filenames
824func Test_mksession_slash()
Bram Moolenaar37ac4a52019-09-28 19:29:04 +0200825 if exists('+shellslash')
826 throw 'Skipped: cannot use backslash in file name'
827 endif
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200828 enew
829 %bwipe!
830 e a\\b\\c
831 mksession! Xtest_mks1.out
832 set sessionoptions+=slash
833 mksession! Xtest_mks2.out
834
835 %bwipe!
836 source Xtest_mks1.out
837 call assert_equal('a\b\c', bufname(''))
838 %bwipe!
839 source Xtest_mks2.out
840 call assert_equal('a/b/c', bufname(''))
841
842 %bwipe!
843 call delete('Xtest_mks1.out')
844 call delete('Xtest_mks2.out')
845 set sessionoptions&
846endfunc
847
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200848" Test for changing directory to the session file directory
849func Test_mksession_sesdir()
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100850 let save_cwd = getcwd()
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200851 call mkdir('Xproj')
852 mksession! Xproj/Xtest_mks1.out
853 set sessionoptions-=curdir
854 set sessionoptions+=sesdir
855 mksession! Xproj/Xtest_mks2.out
856
857 source Xproj/Xtest_mks1.out
858 call assert_equal('testdir', fnamemodify(getcwd(), ':t'))
859 source Xproj/Xtest_mks2.out
860 call assert_equal('Xproj', fnamemodify(getcwd(), ':t'))
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100861 call chdir(save_cwd)
862 %bwipe
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200863
864 set sessionoptions&
865 call delete('Xproj', 'rf')
866endfunc
867
LemonBoyd7c95642022-04-30 16:10:27 +0100868" Test for saving and restoring the tab-local working directory when there is
869" only a single tab and 'tabpages' is not in 'sessionoptions'.
870func Test_mksession_tcd_single_tabs()
871 only | tabonly
872
873 let save_cwd = getcwd()
874 set sessionoptions-=tabpages
875 set sessionoptions+=curdir
876 call mkdir('Xtopdir1')
877 call mkdir('Xtopdir2')
878
879 " There are two tab pages, the current one has local cwd set to 'Xtopdir2'.
880 exec 'tcd ' .. save_cwd .. '/Xtopdir1'
881 tabnew
882 exec 'tcd ' .. save_cwd .. '/Xtopdir2'
883 mksession! Xtest_tcd_single
884
885 source Xtest_tcd_single
886 call assert_equal(2, haslocaldir())
887 call assert_equal('Xtopdir2', fnamemodify(getcwd(-1, 0), ':t'))
888 %bwipe
889
890 set sessionoptions&
891 call chdir(save_cwd)
892 call delete('Xtopdir1', 'rf')
893 call delete('Xtopdir2', 'rf')
894endfunc
895
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200896" Test for storing the 'lines' and 'columns' settings
897func Test_mksession_resize()
898 mksession! Xtest_mks1.out
899 set sessionoptions+=resize
900 mksession! Xtest_mks2.out
901
902 let lines = readfile('Xtest_mks1.out')
903 let found_resize = v:false
904 for line in lines
905 if line =~ '^set lines='
906 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200907 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200908 endif
909 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200910 call assert_false(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200911 let lines = readfile('Xtest_mks2.out')
912 let found_resize = v:false
913 for line in lines
914 if line =~ '^set lines='
915 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200916 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200917 endif
918 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200919 call assert_true(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200920
921 call delete('Xtest_mks1.out')
922 call delete('Xtest_mks2.out')
923 set sessionoptions&
924endfunc
925
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200926" Test for mksession with a named scratch buffer
927func Test_mksession_scratch()
928 enew | only
929 file Xscratch
930 set buftype=nofile
931 mksession! Xtest_mks.out
932 %bwipe
933 source Xtest_mks.out
934 call assert_equal('Xscratch', bufname(''))
935 call assert_equal('nofile', &buftype)
936 %bwipe
937 call delete('Xtest_mks.out')
938endfunc
939
940" Test for mksession with fold options
941func Test_mksession_foldopt()
942 set sessionoptions-=options
943 set sessionoptions+=folds
944 new
945 setlocal foldenable
946 setlocal foldmethod=expr
947 setlocal foldmarker=<<<,>>>
948 setlocal foldignore=%
949 setlocal foldlevel=2
950 setlocal foldminlines=10
951 setlocal foldnestmax=15
952 mksession! Xtest_mks.out
953 close
954 %bwipe
955
956 source Xtest_mks.out
957 call assert_true(&foldenable)
958 call assert_equal('expr', &foldmethod)
959 call assert_equal('<<<,>>>', &foldmarker)
960 call assert_equal('%', &foldignore)
961 call assert_equal(2, &foldlevel)
962 call assert_equal(10, &foldminlines)
963 call assert_equal(15, &foldnestmax)
964
965 close
966 %bwipe
967 set sessionoptions&
968endfunc
969
matveyt8e7d9db2022-01-05 14:01:30 +0000970" Test for mksession with "help" but not "options" in 'sessionoptions'
971func Test_mksession_help_noopt()
972 set sessionoptions-=options
973 set sessionoptions+=help
974 help
975 let fname = expand('%')
976 mksession! Xtest_mks.out
977 bwipe
978
979 source Xtest_mks.out
980 call assert_equal('help', &buftype)
981 call assert_equal('help', &filetype)
982 call assert_equal(fname, expand('%'))
983 call assert_false(&modifiable)
984 call assert_true(&readonly)
985
986 helpclose
987 help index
988 let fname = expand('%')
989 mksession! Xtest_mks.out
990 bwipe
991
992 source Xtest_mks.out
993 call assert_equal('help', &buftype)
994 call assert_equal(fname, expand('%'))
995
996 call delete('Xtest_mks.out')
997 set sessionoptions&
998endfunc
999
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001000" Test for mksession with window position
1001func Test_mksession_winpos()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02001002 " Only applicable in GUI Vim
1003 CheckGui
1004
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001005 set sessionoptions+=winpos
1006 mksession! Xtest_mks.out
1007 let found_winpos = v:false
1008 let lines = readfile('Xtest_mks.out')
1009 for line in lines
1010 if line =~ '^winpos '
1011 let found_winpos = v:true
1012 break
1013 endif
1014 endfor
1015 call assert_true(found_winpos)
1016 call delete('Xtest_mks.out')
1017 set sessionoptions&
1018endfunc
1019
Bram Moolenaar0995c812021-04-17 18:38:54 +02001020" Test for mksession without options restores winminheight
1021func Test_mksession_winminheight()
1022 set sessionoptions-=options
1023 split
1024 mksession! Xtest_mks.out
1025 let found_restore = 0
1026 let lines = readfile('Xtest_mks.out')
1027 for line in lines
1028 if line =~ '= s:save_winmin\(width\|height\)'
1029 let found_restore += 1
1030 endif
1031 endfor
1032 call assert_equal(2, found_restore)
1033 call delete('Xtest_mks.out')
1034 close
1035 set sessionoptions&
1036endfunc
1037
James Chertifd012802022-03-29 12:02:57 +01001038" Test for mksession with and without options restores shortmess
1039func Test_mksession_shortmess()
1040 " Without options
1041 set sessionoptions-=options
1042 split
1043 mksession! Xtest_mks.out
1044 let found_save = 0
1045 let found_restore = 0
1046 let lines = readfile('Xtest_mks.out')
1047 for line in lines
1048 let line = trim(line)
1049
1050 if line ==# 'let s:shortmess_save = &shortmess'
1051 let found_save += 1
1052 endif
1053
1054 if found_save !=# 0 && line ==# 'let &shortmess = s:shortmess_save'
1055 let found_restore += 1
1056 endif
1057 endfor
1058 call assert_equal(1, found_save)
1059 call assert_equal(1, found_restore)
1060 call delete('Xtest_mks.out')
1061 close
1062 set sessionoptions&
1063
1064 " With options
1065 set sessionoptions+=options
1066 split
1067 mksession! Xtest_mks.out
1068 let found_restore = 0
1069 let lines = readfile('Xtest_mks.out')
1070 for line in lines
1071 if line =~# 's:shortmess_save'
1072 let found_restore += 1
1073 endif
1074 endfor
1075 call assert_equal(0, found_restore)
1076 call delete('Xtest_mks.out')
1077 close
1078 set sessionoptions&
1079endfunc
1080
Bram Moolenaaraaadb5b2022-05-18 22:07:47 +01001081" Test that when Vim loading session has 'A' in 'shortmess' it does not
1082" complain about an existing swapfile.
1083func Test_mksession_shortmess_with_A()
1084 edit Xtestfile
1085 write
1086 let fname = swapname('%')
1087 let cont = readblob(fname)
1088 set sessionoptions-=options
1089 mksession Xtestsession
1090 bwipe!
1091
1092 " Recreate the swap file to pretend the file is being edited
1093 call writefile(cont, fname)
1094 set shortmess+=A
1095 source Xtestsession
1096
1097 set shortmess&
1098 set sessionoptions&
1099 call delete('Xtestsession')
1100 call delete(fname)
1101endfunc
1102
Bram Moolenaaree1a2b52019-09-29 14:23:39 +02001103" Test for mksession with 'compatible' option
1104func Test_mksession_compatible()
1105 mksession! Xtest_mks1.out
1106 set compatible
1107 mksession! Xtest_mks2.out
1108 set nocp
1109
1110 let test_success = v:false
1111 let lines = readfile('Xtest_mks1.out')
1112 for line in lines
1113 if line =~ '^if &cp | set nocp | endif'
1114 let test_success = v:true
1115 break
1116 endif
1117 endfor
1118 call assert_true(test_success)
1119
1120 let test_success = v:false
1121 let lines = readfile('Xtest_mks2.out')
1122 for line in lines
1123 if line =~ '^if !&cp | set cp | endif'
1124 let test_success = v:true
1125 break
1126 endif
1127 endfor
1128 call assert_true(test_success)
1129
1130 call delete('Xtest_mks1.out')
1131 call delete('Xtest_mks2.out')
1132 set compatible&
1133 set sessionoptions&
1134endfunc
1135
Bram Moolenaar87500262019-08-01 23:05:49 +02001136func s:ClearMappings()
1137 mapclear
1138 omapclear
1139 mapclear!
1140 lmapclear
1141 tmapclear
1142endfunc
1143
1144func Test_mkvimrc()
1145 let entries = [
1146 \ ['', 'nothing', '<Nop>'],
1147 \ ['n', 'normal', 'NORMAL'],
1148 \ ['v', 'visual', 'VISUAL'],
1149 \ ['s', 'select', 'SELECT'],
1150 \ ['x', 'visualonly', 'VISUALONLY'],
1151 \ ['o', 'operator', 'OPERATOR'],
1152 \ ['i', 'insert', 'INSERT'],
1153 \ ['l', 'lang', 'LANG'],
1154 \ ['c', 'command', 'COMMAND'],
1155 \ ['t', 'terminal', 'TERMINAL'],
1156 \ ]
1157 for entry in entries
1158 exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2]
1159 endfor
1160
1161 mkvimrc Xtestvimrc
1162
1163 call s:ClearMappings()
1164 for entry in entries
1165 call assert_equal('', maparg(entry[1], entry[0]))
1166 endfor
1167
1168 source Xtestvimrc
1169
1170 for entry in entries
1171 call assert_equal(entry[2], maparg(entry[1], entry[0]))
1172 endfor
1173
1174 call s:ClearMappings()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001175
1176 " the 'pastetoggle', 'wildchar' and 'wildcharm' option values should be
1177 " stored as key names in the vimrc file
1178 set pastetoggle=<F5>
1179 set wildchar=<F6>
1180 set wildcharm=<F7>
1181 call assert_fails('mkvimrc Xtestvimrc')
1182 mkvimrc! Xtestvimrc
1183 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set pastetoggle=<F5>'))
1184 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildchar=<F6>'))
1185 call assert_notequal(-1, index(readfile('Xtestvimrc'), 'set wildcharm=<F7>'))
1186 set pastetoggle& wildchar& wildcharm&
1187
Bram Moolenaar87500262019-08-01 23:05:49 +02001188 call delete('Xtestvimrc')
1189endfunc
1190
Bram Moolenaar38890832020-11-01 17:40:54 +01001191func Test_scrolloff()
1192 set sessionoptions+=localoptions
1193 setlocal so=1 siso=1
1194 mksession! Xtest_mks.out
1195 setlocal so=-1 siso=-1
1196 source Xtest_mks.out
1197 call assert_equal(1, &l:so)
1198 call assert_equal(1, &l:siso)
1199 call delete('Xtest_mks.out')
1200 setlocal so& siso&
1201 set sessionoptions&
1202endfunc
1203
Bram Moolenaar3482be62020-11-27 11:00:38 +01001204func Test_altfile()
1205 edit Xone
1206 split Xtwo
1207 edit Xtwoalt
1208 edit #
1209 wincmd w
1210 edit Xonealt
1211 edit #
1212 mksession! Xtest_altfile
1213 only
1214 bwipe Xonealt
1215 bwipe Xtwoalt
1216 bwipe!
1217 source Xtest_altfile
1218 call assert_equal('Xone', bufname())
1219 call assert_equal('Xonealt', bufname('#'))
1220 wincmd w
1221 call assert_equal('Xtwo', bufname())
1222 call assert_equal('Xtwoalt', bufname('#'))
1223 only
1224 bwipe!
Bram Moolenaarac665c22020-12-08 20:39:15 +01001225 call delete('Xtest_altfile')
Bram Moolenaar3482be62020-11-27 11:00:38 +01001226endfunc
1227
Bram Moolenaar5c504f62021-04-01 13:39:51 +02001228" Test for creating views with manual folds
1229func Test_mkview_manual_fold()
1230 call writefile(range(1,10), 'Xfile')
1231 new Xfile
1232 " create recursive folds
1233 5,6fold
1234 4,7fold
1235 mkview Xview
1236 normal zE
1237 source Xview
1238 call assert_equal([-1, 4, 4, 4, 4, -1], [foldclosed(3), foldclosed(4),
1239 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
1240 " open one level of fold
1241 4foldopen
1242 mkview! Xview
1243 normal zE
1244 source Xview
1245 call assert_equal([-1, -1, 5, 5, -1, -1], [foldclosed(3), foldclosed(4),
1246 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
1247 " open all the folds
1248 %foldopen!
1249 mkview! Xview
1250 normal zE
1251 source Xview
1252 call assert_equal([-1, -1, -1, -1, -1, -1], [foldclosed(3), foldclosed(4),
1253 \ foldclosed(5), foldclosed(6), foldclosed(7), foldclosed(8)])
1254 call delete('Xfile')
1255 call delete('Xview')
1256 bw!
1257endfunc
1258
Bram Moolenaareca626f2016-12-01 18:47:38 +01001259" vim: shiftwidth=2 sts=2 expandtab