blob: a3712a37dd448d936688b106cedc6bb9ca1a97bd [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 Moolenaar36ae89c2017-01-28 17:11:14 +0100134func Test_mksession_winheight()
135 new
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200136 set winheight=10
137 set winminheight=2
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100138 mksession! Xtest_mks.out
139 source Xtest_mks.out
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100140
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100141 call delete('Xtest_mks.out')
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100142endfunc
143
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200144func Test_mksession_large_winheight()
145 set winheight=999
146 mksession! Xtest_mks_winheight.out
147 set winheight&
148 source Xtest_mks_winheight.out
149 call delete('Xtest_mks_winheight.out')
150endfunc
151
Bram Moolenaared18f2c2019-01-24 20:30:52 +0100152func Test_mksession_rtp()
Bram Moolenaar681b6bc2019-01-24 22:23:58 +0100153 if has('win32')
154 " TODO: fix problem with backslashes
155 return
156 endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +0100157 new
158 let _rtp=&rtp
159 " Make a real long (invalid) runtimepath value,
160 " that should exceed PATH_MAX (hopefully)
161 let newrtp=&rtp.',~'.repeat('/foobar', 1000)
162 let newrtp.=",".expand("$HOME")."/.vim"
163 let &rtp=newrtp
164
165 " determine expected value
166 let expected=split(&rtp, ',')
167 let expected = map(expected, '"set runtimepath+=".v:val')
168 let expected = ['set runtimepath='] + expected
169 let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")})
170
171 mksession! Xtest_mks.out
172 let &rtp=_rtp
173 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"')
174 call assert_equal(expected, li)
175
176 call delete('Xtest_mks.out')
177endfunc
178
Bram Moolenaar79da5632017-02-01 22:52:44 +0100179func Test_mksession_arglist()
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200180 %argdel
Bram Moolenaar79da5632017-02-01 22:52:44 +0100181 next file1 file2 file3 file4
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200182 new
183 next | next
Bram Moolenaar79da5632017-02-01 22:52:44 +0100184 mksession! Xtest_mks.out
185 source Xtest_mks.out
186 call assert_equal(['file1', 'file2', 'file3', 'file4'], argv())
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200187 call assert_equal(2, argidx())
188 wincmd w
189 call assert_equal(0, argidx())
Bram Moolenaar79da5632017-02-01 22:52:44 +0100190
191 call delete('Xtest_mks.out')
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200192 enew | only
Bram Moolenaar79da5632017-02-01 22:52:44 +0100193 argdel *
194endfunc
195
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200196func Test_mksession_one_buffer_two_windows()
197 edit Xtest1
198 new Xtest2
199 split
200 mksession! Xtest_mks.out
201 let lines = readfile('Xtest_mks.out')
202 let count1 = 0
203 let count2 = 0
204 let count2buf = 0
205 for line in lines
206 if line =~ 'edit \f*Xtest1$'
207 let count1 += 1
208 endif
209 if line =~ 'edit \f\{-}Xtest2'
210 let count2 += 1
211 endif
212 if line =~ 'buffer \f\{-}Xtest2'
213 let count2buf += 1
214 endif
215 endfor
216 call assert_equal(1, count1, 'Xtest1 count')
217 call assert_equal(2, count2, 'Xtest2 count')
218 call assert_equal(2, count2buf, 'Xtest2 buffer count')
219
220 close
221 bwipe!
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200222 call delete('Xtest_mks.out')
223endfunc
224
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200225func Test_mksession_lcd_multiple_tabs()
226 tabnew
227 tabnew
Bram Moolenaar81e2ac72018-07-04 22:44:08 +0200228 lcd .
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200229 tabfirst
Bram Moolenaar81e2ac72018-07-04 22:44:08 +0200230 lcd .
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200231 mksession! Xtest_mks.out
232 tabonly
233 source Xtest_mks.out
234 call assert_true(haslocaldir(), 'Tab 1 localdir')
235 tabnext 2
236 call assert_true(!haslocaldir(), 'Tab 2 localdir')
237 tabnext 3
238 call assert_true(haslocaldir(), 'Tab 3 localdir')
239 call delete('Xtest_mks.out')
240endfunc
241
Bram Moolenaar00aa0692019-04-27 20:37:57 +0200242" Test for tabpage-local directory
243func Test_mksession_tcd_multiple_tabs()
244 let save_cwd = getcwd()
245 call mkdir('Xtopdir')
246 cd Xtopdir
247 call mkdir('Xtabdir1')
248 call mkdir('Xtabdir2')
249 call mkdir('Xtabdir3')
250 call mkdir('Xwindir1')
251 call mkdir('Xwindir2')
252 call mkdir('Xwindir3')
253 tcd Xtabdir1
254 botright new
255 wincmd t
256 lcd ../Xwindir1
257 tabnew
258 tcd ../Xtabdir2
259 botright new
260 lcd ../Xwindir2
261 tabnew
262 tcd ../Xtabdir3
263 botright new
264 lcd ../Xwindir3
265 tabfirst
266 1wincmd w
267 mksession! Xtest_mks.out
268 only | tabonly
269 source Xtest_mks.out
270 call assert_equal('Xtabdir1', fnamemodify(getcwd(-1, 1), ':t'))
271 call assert_equal('Xwindir1', fnamemodify(getcwd(1, 1), ':t'))
272 call assert_equal('Xtabdir1', fnamemodify(getcwd(2, 1), ':t'))
273 call assert_equal('Xtabdir2', fnamemodify(getcwd(-1, 2), ':t'))
274 call assert_equal('Xtabdir2', fnamemodify(getcwd(1, 2), ':t'))
275 call assert_equal('Xwindir2', fnamemodify(getcwd(2, 2), ':t'))
276 call assert_equal('Xtabdir3', fnamemodify(getcwd(-1, 3), ':t'))
277 call assert_equal('Xtabdir3', fnamemodify(getcwd(1, 3), ':t'))
278 call assert_equal('Xwindir3', fnamemodify(getcwd(2, 3), ':t'))
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100279 %bwipe
280 call chdir(save_cwd)
Bram Moolenaar00aa0692019-04-27 20:37:57 +0200281 call delete("Xtopdir", "rf")
282endfunc
283
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200284func Test_mksession_blank_tabs()
285 tabnew
286 tabnew
287 tabnew
288 tabnext 3
289 mksession! Xtest_mks.out
290 tabnew
291 tabnew
292 tabnext 2
293 source Xtest_mks.out
294 call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs')
295 call assert_equal(3, tabpagenr(), 'session restore should restore the active tab')
296 call delete('Xtest_mks.out')
297endfunc
298
Bram Moolenaard39e2752019-01-26 20:07:38 +0100299func Test_mksession_buffer_count()
300 set hidden
301
302 " Edit exactly three files in the current session.
303 %bwipe!
304 e Xfoo | tabe Xbar | tabe Xbaz
305 tabdo write
306 mksession! Xtest_mks.out
307
308 " Verify that loading the session does not create additional buffers.
309 %bwipe!
310 source Xtest_mks.out
311 call assert_equal(3, len(getbufinfo()))
312
313 " Clean up.
314 call delete('Xfoo')
315 call delete('Xbar')
316 call delete('Xbaz')
317 call delete('Xtest_mks.out')
318 %bwipe!
319 set hidden&
320endfunc
321
Bram Moolenaare3c74d22019-01-12 16:29:30 +0100322if has('extra_search')
323
324func Test_mksession_hlsearch()
325 set hlsearch
326 mksession! Xtest_mks.out
327 nohlsearch
328 source Xtest_mks.out
329 call assert_equal(1, v:hlsearch, 'session should restore search highlighting state')
330 nohlsearch
331 mksession! Xtest_mks.out
332 source Xtest_mks.out
333 call assert_equal(0, v:hlsearch, 'session should restore search highlighting state')
334 call delete('Xtest_mks.out')
335endfunc
336
337endif
338
339
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200340func Test_mksession_blank_windows()
341 split
342 split
343 split
344 3 wincmd w
345 mksession! Xtest_mks.out
346 split
347 split
348 2 wincmd w
349 source Xtest_mks.out
350 call assert_equal(4, winnr('$'), 'session restore should restore number of windows')
351 call assert_equal(3, winnr(), 'session restore should restore the active window')
352 call delete('Xtest_mks.out')
353endfunc
354
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100355if has('terminal')
356
357func Test_mksession_terminal_shell()
358 terminal
359 mksession! Xtest_mks.out
360 let lines = readfile('Xtest_mks.out')
361 let term_cmd = ''
362 for line in lines
363 if line =~ '^terminal'
364 let term_cmd = line
365 elseif line =~ 'badd.*' . &shell
366 call assert_report('unexpected shell line: ' . line)
367 endif
368 endfor
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +0100369 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd)
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100370
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200371 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100372 call delete('Xtest_mks.out')
373endfunc
374
375func Test_mksession_terminal_no_restore_cmdarg()
376 terminal ++norestore
377 mksession! Xtest_mks.out
378 let lines = readfile('Xtest_mks.out')
379 let term_cmd = ''
380 for line in lines
381 if line =~ '^terminal'
382 call assert_report('session must not restore teminal')
383 endif
384 endfor
385
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200386 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100387 call delete('Xtest_mks.out')
388endfunc
389
390func Test_mksession_terminal_no_restore_funcarg()
391 call term_start(&shell, {'norestore': 1})
392 mksession! Xtest_mks.out
393 let lines = readfile('Xtest_mks.out')
394 let term_cmd = ''
395 for line in lines
396 if line =~ '^terminal'
397 call assert_report('session must not restore teminal')
398 endif
399 endfor
400
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200401 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100402 call delete('Xtest_mks.out')
403endfunc
404
405func Test_mksession_terminal_no_restore_func()
406 terminal
407 call term_setrestore(bufnr('%'), 'NONE')
408 mksession! Xtest_mks.out
409 let lines = readfile('Xtest_mks.out')
410 let term_cmd = ''
411 for line in lines
412 if line =~ '^terminal'
413 call assert_report('session must not restore teminal')
414 endif
415 endfor
416
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200417 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100418 call delete('Xtest_mks.out')
419endfunc
420
421func Test_mksession_terminal_no_ssop()
422 terminal
423 set sessionoptions-=terminal
424 mksession! Xtest_mks.out
425 let lines = readfile('Xtest_mks.out')
426 let term_cmd = ''
427 for line in lines
428 if line =~ '^terminal'
429 call assert_report('session must not restore teminal')
430 endif
431 endfor
432
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200433 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100434 call delete('Xtest_mks.out')
435 set sessionoptions&
436endfunc
437
438func Test_mksession_terminal_restore_other()
439 terminal
Bram Moolenaar7ee80f72019-09-08 20:55:06 +0200440 eval bufnr('%')->term_setrestore('other')
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100441 mksession! Xtest_mks.out
442 let lines = readfile('Xtest_mks.out')
443 let term_cmd = ''
444 for line in lines
445 if line =~ '^terminal'
446 let term_cmd = line
447 endif
448 endfor
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +0100449 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd)
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100450
Bram Moolenaar7a39dd72019-06-23 00:50:15 +0200451 call StopShellInTerminal(bufnr('%'))
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100452 call delete('Xtest_mks.out')
453endfunc
454
455endif " has('terminal')
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200456
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200457" Test :mkview with a file argument.
458func Test_mkview_file()
459 " Create a view with line number and a fold.
460 help :mkview
461 set number
Bram Moolenaar2bf4fe02018-08-30 14:04:25 +0200462 norm! V}zf0
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200463 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200464 let linefoldclosed1 = foldclosed('.')
465 mkview! Xview
466 set nonumber
467 norm! zrj
468 " We can close the help window, as mkview with a file name should
469 " generate a command to edit the file.
470 helpclose
471
472 source Xview
473 call assert_equal(1, &number)
474 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200475 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200476 call assert_equal(linefoldclosed1, foldclosed('.'))
477
478 " Creating a view again with the same file name should fail (file
479 " already exists). But with a !, the previous view should be
480 " overwritten without error.
481 help :loadview
482 call assert_fails('mkview Xview', 'E189:')
483 call assert_match('\*:loadview\*$', getline('.'))
484 mkview! Xview
485 call assert_match('\*:loadview\*$', getline('.'))
486
487 call delete('Xview')
488 bwipe
489endfunc
490
491" Test :mkview and :loadview with a custom 'viewdir'.
492func Test_mkview_loadview_with_viewdir()
493 set viewdir=Xviewdir
494
495 help :mkview
496 set number
497 norm! V}zf
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200498 let pos = getpos('.')
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200499 let linefoldclosed1 = foldclosed('.')
500 mkview 1
501 set nonumber
502 norm! zrj
503
504 loadview 1
505
506 " The directory Xviewdir/ should have been created and the view
507 " should be stored in that directory.
508 call assert_equal('Xviewdir/' .
509 \ substitute(
510 \ substitute(
511 \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim',
512 \ glob('Xviewdir/*'))
513 call assert_equal(1, &number)
514 call assert_match('\*:mkview\*$', getline('.'))
Bram Moolenaardd5d18e2018-08-30 14:16:06 +0200515 call assert_equal(pos, getpos('.'))
Bram Moolenaar627cb6a2018-08-28 22:19:31 +0200516 call assert_equal(linefoldclosed1, foldclosed('.'))
517
518 call delete('Xviewdir', 'rf')
519 set viewdir&
520 helpclose
521endfunc
522
523func Test_mkview_no_file_name()
524 new
525 " :mkview or :mkview {nr} should fail in a unnamed buffer.
526 call assert_fails('mkview', 'E32:')
527 call assert_fails('mkview 1', 'E32:')
528
529 " :mkview {file} should succeed in a unnamed buffer.
530 mkview Xview
531 help
532 source Xview
533 call assert_equal('', bufname('%'))
534
535 call delete('Xview')
536 %bwipe
537endfunc
Bram Moolenaar79da5632017-02-01 22:52:44 +0100538
Bram Moolenaar555de4e2019-01-21 23:03:49 +0100539" A clean session (one empty buffer, one window, and one tab) should not
540" set any error messages when sourced because no commands should fail.
541func Test_mksession_no_errmsg()
542 let v:errmsg = ''
543 %bwipe!
544 mksession! Xtest_mks.out
545 source Xtest_mks.out
546 call assert_equal('', v:errmsg)
547 call delete('Xtest_mks.out')
548endfunc
549
Bram Moolenaarad36a352019-01-24 13:34:42 +0100550func Test_mksession_quote_in_filename()
Bram Moolenaar9e79ccb2019-01-24 15:57:30 +0100551 if !has('unix')
552 " only Unix can handle this weird filename
553 return
554 endif
Bram Moolenaarad36a352019-01-24 13:34:42 +0100555 let v:errmsg = ''
556 %bwipe!
557 split another
558 split x'y\"z
559 mksession! Xtest_mks_quoted.out
560 %bwipe!
561 source Xtest_mks_quoted.out
562 call assert_true(bufexists("x'y\"z"))
563
564 %bwipe!
565 call delete('Xtest_mks_quoted.out')
566endfunc
567
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200568" Test for storing global variables in a session file
569func Test_mksession_globals()
570 set sessionoptions+=globals
571
572 " create different global variables
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200573 let g:Global_string = "Sun is shining\r\n"
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200574 let g:Global_count = 100
575 let g:Global_pi = 3.14
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200576 let g:Global_neg_float = -2.68
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200577
578 mksession! Xtest_mks.out
579
580 unlet g:Global_string
581 unlet g:Global_count
582 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200583 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200584
585 source Xtest_mks.out
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200586 call assert_equal("Sun is shining\r\n", g:Global_string)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200587 call assert_equal(100, g:Global_count)
588 call assert_equal(3.14, g:Global_pi)
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200589 call assert_equal(-2.68, g:Global_neg_float)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200590
591 unlet g:Global_string
592 unlet g:Global_count
593 unlet g:Global_pi
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200594 unlet g:Global_neg_float
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200595 call delete('Xtest_mks.out')
596 set sessionoptions&
597endfunc
598
599" Test for changing backslash to forward slash in filenames
600func Test_mksession_slash()
Bram Moolenaar37ac4a52019-09-28 19:29:04 +0200601 if exists('+shellslash')
602 throw 'Skipped: cannot use backslash in file name'
603 endif
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200604 enew
605 %bwipe!
606 e a\\b\\c
607 mksession! Xtest_mks1.out
608 set sessionoptions+=slash
609 mksession! Xtest_mks2.out
610
611 %bwipe!
612 source Xtest_mks1.out
613 call assert_equal('a\b\c', bufname(''))
614 %bwipe!
615 source Xtest_mks2.out
616 call assert_equal('a/b/c', bufname(''))
617
618 %bwipe!
619 call delete('Xtest_mks1.out')
620 call delete('Xtest_mks2.out')
621 set sessionoptions&
622endfunc
623
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200624" Test for changing directory to the session file directory
625func Test_mksession_sesdir()
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100626 let save_cwd = getcwd()
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200627 call mkdir('Xproj')
628 mksession! Xproj/Xtest_mks1.out
629 set sessionoptions-=curdir
630 set sessionoptions+=sesdir
631 mksession! Xproj/Xtest_mks2.out
632
633 source Xproj/Xtest_mks1.out
634 call assert_equal('testdir', fnamemodify(getcwd(), ':t'))
635 source Xproj/Xtest_mks2.out
636 call assert_equal('Xproj', fnamemodify(getcwd(), ':t'))
Bram Moolenaar5bf46e92019-11-09 18:06:04 +0100637 call chdir(save_cwd)
638 %bwipe
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200639
640 set sessionoptions&
641 call delete('Xproj', 'rf')
642endfunc
643
644" Test for storing the 'lines' and 'columns' settings
645func Test_mksession_resize()
646 mksession! Xtest_mks1.out
647 set sessionoptions+=resize
648 mksession! Xtest_mks2.out
649
650 let lines = readfile('Xtest_mks1.out')
651 let found_resize = v:false
652 for line in lines
653 if line =~ '^set lines='
654 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200655 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200656 endif
657 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200658 call assert_false(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200659 let lines = readfile('Xtest_mks2.out')
660 let found_resize = v:false
661 for line in lines
662 if line =~ '^set lines='
663 let found_resize = v:true
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200664 break
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200665 endif
666 endfor
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200667 call assert_true(found_resize)
Bram Moolenaar66f0e6c2019-09-28 19:08:45 +0200668
669 call delete('Xtest_mks1.out')
670 call delete('Xtest_mks2.out')
671 set sessionoptions&
672endfunc
673
Bram Moolenaaree1a2b52019-09-29 14:23:39 +0200674" Test for mksession with a named scratch buffer
675func Test_mksession_scratch()
676 enew | only
677 file Xscratch
678 set buftype=nofile
679 mksession! Xtest_mks.out
680 %bwipe
681 source Xtest_mks.out
682 call assert_equal('Xscratch', bufname(''))
683 call assert_equal('nofile', &buftype)
684 %bwipe
685 call delete('Xtest_mks.out')
686endfunc
687
688" Test for mksession with fold options
689func Test_mksession_foldopt()
690 set sessionoptions-=options
691 set sessionoptions+=folds
692 new
693 setlocal foldenable
694 setlocal foldmethod=expr
695 setlocal foldmarker=<<<,>>>
696 setlocal foldignore=%
697 setlocal foldlevel=2
698 setlocal foldminlines=10
699 setlocal foldnestmax=15
700 mksession! Xtest_mks.out
701 close
702 %bwipe
703
704 source Xtest_mks.out
705 call assert_true(&foldenable)
706 call assert_equal('expr', &foldmethod)
707 call assert_equal('<<<,>>>', &foldmarker)
708 call assert_equal('%', &foldignore)
709 call assert_equal(2, &foldlevel)
710 call assert_equal(10, &foldminlines)
711 call assert_equal(15, &foldnestmax)
712
713 close
714 %bwipe
715 set sessionoptions&
716endfunc
717
718" Test for mksession with window position
719func Test_mksession_winpos()
720 if !has('gui_running')
721 " Only applicable in GUI Vim
722 return
723 endif
724 set sessionoptions+=winpos
725 mksession! Xtest_mks.out
726 let found_winpos = v:false
727 let lines = readfile('Xtest_mks.out')
728 for line in lines
729 if line =~ '^winpos '
730 let found_winpos = v:true
731 break
732 endif
733 endfor
734 call assert_true(found_winpos)
735 call delete('Xtest_mks.out')
736 set sessionoptions&
737endfunc
738
739" Test for mksession with 'compatible' option
740func Test_mksession_compatible()
741 mksession! Xtest_mks1.out
742 set compatible
743 mksession! Xtest_mks2.out
744 set nocp
745
746 let test_success = v:false
747 let lines = readfile('Xtest_mks1.out')
748 for line in lines
749 if line =~ '^if &cp | set nocp | endif'
750 let test_success = v:true
751 break
752 endif
753 endfor
754 call assert_true(test_success)
755
756 let test_success = v:false
757 let lines = readfile('Xtest_mks2.out')
758 for line in lines
759 if line =~ '^if !&cp | set cp | endif'
760 let test_success = v:true
761 break
762 endif
763 endfor
764 call assert_true(test_success)
765
766 call delete('Xtest_mks1.out')
767 call delete('Xtest_mks2.out')
768 set compatible&
769 set sessionoptions&
770endfunc
771
Bram Moolenaar87500262019-08-01 23:05:49 +0200772func s:ClearMappings()
773 mapclear
774 omapclear
775 mapclear!
776 lmapclear
777 tmapclear
778endfunc
779
780func Test_mkvimrc()
781 let entries = [
782 \ ['', 'nothing', '<Nop>'],
783 \ ['n', 'normal', 'NORMAL'],
784 \ ['v', 'visual', 'VISUAL'],
785 \ ['s', 'select', 'SELECT'],
786 \ ['x', 'visualonly', 'VISUALONLY'],
787 \ ['o', 'operator', 'OPERATOR'],
788 \ ['i', 'insert', 'INSERT'],
789 \ ['l', 'lang', 'LANG'],
790 \ ['c', 'command', 'COMMAND'],
791 \ ['t', 'terminal', 'TERMINAL'],
792 \ ]
793 for entry in entries
794 exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2]
795 endfor
796
797 mkvimrc Xtestvimrc
798
799 call s:ClearMappings()
800 for entry in entries
801 call assert_equal('', maparg(entry[1], entry[0]))
802 endfor
803
804 source Xtestvimrc
805
806 for entry in entries
807 call assert_equal(entry[2], maparg(entry[1], entry[0]))
808 endfor
809
810 call s:ClearMappings()
811 call delete('Xtestvimrc')
812endfunc
813
Bram Moolenaareca626f2016-12-01 18:47:38 +0100814" vim: shiftwidth=2 sts=2 expandtab