blob: 49d89ecc9a3d6f6947eac3a60ac61228c51c192c [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
6if !has('multi_byte') || !has('mksession')
7 finish
8endif
9
Bram Moolenaar4d8bac82018-03-09 21:33:34 +010010source shared.vim
11
Bram Moolenaareca626f2016-12-01 18:47:38 +010012func Test_mksession()
13 tabnew
14 let wrap_save = &wrap
15 set sessionoptions=buffers splitbelow fileencoding=latin1
16 call setline(1, [
17 \ 'start:',
18 \ 'no multibyte chAracter',
19 \ ' one leaDing tab',
20 \ ' four leadinG spaces',
21 \ 'two consecutive tabs',
22 \ 'two tabs in one line',
23 \ 'one ä multibyteCharacter',
24 \ 'aä Ä two multiByte characters',
25 \ 'Aäöü three mulTibyte characters'
26 \ ])
Bram Moolenaarc9b56b22017-01-29 14:14:09 +010027 let tmpfile = 'Xtemp'
Bram Moolenaareca626f2016-12-01 18:47:38 +010028 exec 'w! ' . tmpfile
29 /^start:
30 set wrap
31 vsplit
32 norm! j16|
33 split
34 norm! j16|
35 split
36 norm! j16|
37 split
38 norm! j8|
39 split
40 norm! j8|
41 split
42 norm! j16|
43 split
44 norm! j16|
45 split
46 norm! j16|
47 wincmd l
48
49 set nowrap
50 /^start:
51 norm! j16|3zl
52 split
53 norm! j016|3zl
54 split
55 norm! j016|3zl
56 split
57 norm! j08|3zl
58 split
59 norm! j08|3zl
60 split
61 norm! j016|3zl
62 split
63 norm! j016|3zl
64 split
65 norm! j016|3zl
66 split
67 call wincol()
Bram Moolenaarc9b56b22017-01-29 14:14:09 +010068 mksession! Xtest_mks.out
69 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! 0\\|^ *exe ''normal!\\)"')
Bram Moolenaareca626f2016-12-01 18:47:38 +010070 let expected = [
71 \ 'normal! 016|',
72 \ 'normal! 016|',
73 \ 'normal! 016|',
74 \ 'normal! 08|',
75 \ 'normal! 08|',
76 \ 'normal! 016|',
77 \ 'normal! 016|',
78 \ 'normal! 016|',
79 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
80 \ " normal! 016|",
81 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
82 \ " normal! 016|",
83 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
84 \ " normal! 016|",
85 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'",
86 \ " normal! 08|",
87 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'",
88 \ " normal! 08|",
89 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
90 \ " normal! 016|",
91 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
92 \ " normal! 016|",
93 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
94 \ " normal! 016|",
95 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
96 \ " normal! 016|"
97 \ ]
98 call assert_equal(expected, li)
99 tabclose!
100
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100101 call delete('Xtest_mks.out')
Bram Moolenaareca626f2016-12-01 18:47:38 +0100102 call delete(tmpfile)
103 let &wrap = wrap_save
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100104 set sessionoptions&
Bram Moolenaareca626f2016-12-01 18:47:38 +0100105endfunc
106
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100107func Test_mksession_winheight()
108 new
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200109 set winheight=10
110 set winminheight=2
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100111 mksession! Xtest_mks.out
112 source Xtest_mks.out
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100113
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100114 call delete('Xtest_mks.out')
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100115endfunc
116
Bram Moolenaar1c3c1042018-06-12 16:49:30 +0200117func Test_mksession_large_winheight()
118 set winheight=999
119 mksession! Xtest_mks_winheight.out
120 set winheight&
121 source Xtest_mks_winheight.out
122 call delete('Xtest_mks_winheight.out')
123endfunc
124
Bram Moolenaar79da5632017-02-01 22:52:44 +0100125func Test_mksession_arglist()
126 argdel *
127 next file1 file2 file3 file4
128 mksession! Xtest_mks.out
129 source Xtest_mks.out
130 call assert_equal(['file1', 'file2', 'file3', 'file4'], argv())
131
132 call delete('Xtest_mks.out')
133 argdel *
134endfunc
135
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200136func Test_mksession_one_buffer_two_windows()
137 edit Xtest1
138 new Xtest2
139 split
140 mksession! Xtest_mks.out
141 let lines = readfile('Xtest_mks.out')
142 let count1 = 0
143 let count2 = 0
144 let count2buf = 0
145 for line in lines
146 if line =~ 'edit \f*Xtest1$'
147 let count1 += 1
148 endif
149 if line =~ 'edit \f\{-}Xtest2'
150 let count2 += 1
151 endif
152 if line =~ 'buffer \f\{-}Xtest2'
153 let count2buf += 1
154 endif
155 endfor
156 call assert_equal(1, count1, 'Xtest1 count')
157 call assert_equal(2, count2, 'Xtest2 count')
158 call assert_equal(2, count2buf, 'Xtest2 buffer count')
159
160 close
161 bwipe!
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200162 call delete('Xtest_mks.out')
163endfunc
164
Bram Moolenaar26d4b892018-07-04 22:26:28 +0200165func Test_mksession_lcd_multiple_tabs()
166 tabnew
167 tabnew
168 lcd
169 tabfirst
170 lcd
171 mksession! Xtest_mks.out
172 tabonly
173 source Xtest_mks.out
174 call assert_true(haslocaldir(), 'Tab 1 localdir')
175 tabnext 2
176 call assert_true(!haslocaldir(), 'Tab 2 localdir')
177 tabnext 3
178 call assert_true(haslocaldir(), 'Tab 3 localdir')
179 call delete('Xtest_mks.out')
180endfunc
181
182func Test_mksession_blank_tabs()
183 tabnew
184 tabnew
185 tabnew
186 tabnext 3
187 mksession! Xtest_mks.out
188 tabnew
189 tabnew
190 tabnext 2
191 source Xtest_mks.out
192 call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs')
193 call assert_equal(3, tabpagenr(), 'session restore should restore the active tab')
194 call delete('Xtest_mks.out')
195endfunc
196
197func Test_mksession_blank_windows()
198 split
199 split
200 split
201 3 wincmd w
202 mksession! Xtest_mks.out
203 split
204 split
205 2 wincmd w
206 source Xtest_mks.out
207 call assert_equal(4, winnr('$'), 'session restore should restore number of windows')
208 call assert_equal(3, winnr(), 'session restore should restore the active window')
209 call delete('Xtest_mks.out')
210endfunc
211
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100212if has('terminal')
213
214func Test_mksession_terminal_shell()
215 terminal
216 mksession! Xtest_mks.out
217 let lines = readfile('Xtest_mks.out')
218 let term_cmd = ''
219 for line in lines
220 if line =~ '^terminal'
221 let term_cmd = line
222 elseif line =~ 'badd.*' . &shell
223 call assert_report('unexpected shell line: ' . line)
224 endif
225 endfor
226 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*$', term_cmd)
227
228 call Stop_shell_in_terminal(bufnr('%'))
229 call delete('Xtest_mks.out')
230endfunc
231
232func Test_mksession_terminal_no_restore_cmdarg()
233 terminal ++norestore
234 mksession! Xtest_mks.out
235 let lines = readfile('Xtest_mks.out')
236 let term_cmd = ''
237 for line in lines
238 if line =~ '^terminal'
239 call assert_report('session must not restore teminal')
240 endif
241 endfor
242
243 call Stop_shell_in_terminal(bufnr('%'))
244 call delete('Xtest_mks.out')
245endfunc
246
247func Test_mksession_terminal_no_restore_funcarg()
248 call term_start(&shell, {'norestore': 1})
249 mksession! Xtest_mks.out
250 let lines = readfile('Xtest_mks.out')
251 let term_cmd = ''
252 for line in lines
253 if line =~ '^terminal'
254 call assert_report('session must not restore teminal')
255 endif
256 endfor
257
258 call Stop_shell_in_terminal(bufnr('%'))
259 call delete('Xtest_mks.out')
260endfunc
261
262func Test_mksession_terminal_no_restore_func()
263 terminal
264 call term_setrestore(bufnr('%'), 'NONE')
265 mksession! Xtest_mks.out
266 let lines = readfile('Xtest_mks.out')
267 let term_cmd = ''
268 for line in lines
269 if line =~ '^terminal'
270 call assert_report('session must not restore teminal')
271 endif
272 endfor
273
274 call Stop_shell_in_terminal(bufnr('%'))
275 call delete('Xtest_mks.out')
276endfunc
277
278func Test_mksession_terminal_no_ssop()
279 terminal
280 set sessionoptions-=terminal
281 mksession! Xtest_mks.out
282 let lines = readfile('Xtest_mks.out')
283 let term_cmd = ''
284 for line in lines
285 if line =~ '^terminal'
286 call assert_report('session must not restore teminal')
287 endif
288 endfor
289
290 call Stop_shell_in_terminal(bufnr('%'))
291 call delete('Xtest_mks.out')
292 set sessionoptions&
293endfunc
294
295func Test_mksession_terminal_restore_other()
296 terminal
297 call term_setrestore(bufnr('%'), 'other')
298 mksession! Xtest_mks.out
299 let lines = readfile('Xtest_mks.out')
300 let term_cmd = ''
301 for line in lines
302 if line =~ '^terminal'
303 let term_cmd = line
304 endif
305 endfor
306 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+ other', term_cmd)
307
308 call Stop_shell_in_terminal(bufnr('%'))
309 call delete('Xtest_mks.out')
310endfunc
311
312endif " has('terminal')
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200313
Bram Moolenaar79da5632017-02-01 22:52:44 +0100314
Bram Moolenaareca626f2016-12-01 18:47:38 +0100315" vim: shiftwidth=2 sts=2 expandtab