blob: e81d9b3e321faca0be5ace6228c1bb65d5d6ffa0 [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 Moolenaar4d8bac82018-03-09 21:33:34 +0100165if has('terminal')
166
167func Test_mksession_terminal_shell()
168 terminal
169 mksession! Xtest_mks.out
170 let lines = readfile('Xtest_mks.out')
171 let term_cmd = ''
172 for line in lines
173 if line =~ '^terminal'
174 let term_cmd = line
175 elseif line =~ 'badd.*' . &shell
176 call assert_report('unexpected shell line: ' . line)
177 endif
178 endfor
179 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*$', term_cmd)
180
181 call Stop_shell_in_terminal(bufnr('%'))
182 call delete('Xtest_mks.out')
183endfunc
184
185func Test_mksession_terminal_no_restore_cmdarg()
186 terminal ++norestore
187 mksession! Xtest_mks.out
188 let lines = readfile('Xtest_mks.out')
189 let term_cmd = ''
190 for line in lines
191 if line =~ '^terminal'
192 call assert_report('session must not restore teminal')
193 endif
194 endfor
195
196 call Stop_shell_in_terminal(bufnr('%'))
197 call delete('Xtest_mks.out')
198endfunc
199
200func Test_mksession_terminal_no_restore_funcarg()
201 call term_start(&shell, {'norestore': 1})
202 mksession! Xtest_mks.out
203 let lines = readfile('Xtest_mks.out')
204 let term_cmd = ''
205 for line in lines
206 if line =~ '^terminal'
207 call assert_report('session must not restore teminal')
208 endif
209 endfor
210
211 call Stop_shell_in_terminal(bufnr('%'))
212 call delete('Xtest_mks.out')
213endfunc
214
215func Test_mksession_terminal_no_restore_func()
216 terminal
217 call term_setrestore(bufnr('%'), 'NONE')
218 mksession! Xtest_mks.out
219 let lines = readfile('Xtest_mks.out')
220 let term_cmd = ''
221 for line in lines
222 if line =~ '^terminal'
223 call assert_report('session must not restore teminal')
224 endif
225 endfor
226
227 call Stop_shell_in_terminal(bufnr('%'))
228 call delete('Xtest_mks.out')
229endfunc
230
231func Test_mksession_terminal_no_ssop()
232 terminal
233 set sessionoptions-=terminal
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')
245 set sessionoptions&
246endfunc
247
248func Test_mksession_terminal_restore_other()
249 terminal
250 call term_setrestore(bufnr('%'), 'other')
251 mksession! Xtest_mks.out
252 let lines = readfile('Xtest_mks.out')
253 let term_cmd = ''
254 for line in lines
255 if line =~ '^terminal'
256 let term_cmd = line
257 endif
258 endfor
259 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+ other', term_cmd)
260
261 call Stop_shell_in_terminal(bufnr('%'))
262 call delete('Xtest_mks.out')
263endfunc
264
265endif " has('terminal')
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200266
Bram Moolenaar79da5632017-02-01 22:52:44 +0100267
Bram Moolenaareca626f2016-12-01 18:47:38 +0100268" vim: shiftwidth=2 sts=2 expandtab