blob: 81883b5d76f4df93d86114ec51f63fc10f7c5953 [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
109 set winheight=10 winminheight=2
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100110 mksession! Xtest_mks.out
111 source Xtest_mks.out
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100112
Bram Moolenaarc9b56b22017-01-29 14:14:09 +0100113 call delete('Xtest_mks.out')
Bram Moolenaar36ae89c2017-01-28 17:11:14 +0100114endfunc
115
Bram Moolenaar79da5632017-02-01 22:52:44 +0100116func Test_mksession_arglist()
117 argdel *
118 next file1 file2 file3 file4
119 mksession! Xtest_mks.out
120 source Xtest_mks.out
121 call assert_equal(['file1', 'file2', 'file3', 'file4'], argv())
122
123 call delete('Xtest_mks.out')
124 argdel *
125endfunc
126
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200127func Test_mksession_one_buffer_two_windows()
128 edit Xtest1
129 new Xtest2
130 split
131 mksession! Xtest_mks.out
132 let lines = readfile('Xtest_mks.out')
133 let count1 = 0
134 let count2 = 0
135 let count2buf = 0
136 for line in lines
137 if line =~ 'edit \f*Xtest1$'
138 let count1 += 1
139 endif
140 if line =~ 'edit \f\{-}Xtest2'
141 let count2 += 1
142 endif
143 if line =~ 'buffer \f\{-}Xtest2'
144 let count2buf += 1
145 endif
146 endfor
147 call assert_equal(1, count1, 'Xtest1 count')
148 call assert_equal(2, count2, 'Xtest2 count')
149 call assert_equal(2, count2buf, 'Xtest2 buffer count')
150
151 close
152 bwipe!
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200153 call delete('Xtest_mks.out')
154endfunc
155
Bram Moolenaar4d8bac82018-03-09 21:33:34 +0100156if has('terminal')
157
158func Test_mksession_terminal_shell()
159 terminal
160 mksession! Xtest_mks.out
161 let lines = readfile('Xtest_mks.out')
162 let term_cmd = ''
163 for line in lines
164 if line =~ '^terminal'
165 let term_cmd = line
166 elseif line =~ 'badd.*' . &shell
167 call assert_report('unexpected shell line: ' . line)
168 endif
169 endfor
170 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*$', term_cmd)
171
172 call Stop_shell_in_terminal(bufnr('%'))
173 call delete('Xtest_mks.out')
174endfunc
175
176func Test_mksession_terminal_no_restore_cmdarg()
177 terminal ++norestore
178 mksession! Xtest_mks.out
179 let lines = readfile('Xtest_mks.out')
180 let term_cmd = ''
181 for line in lines
182 if line =~ '^terminal'
183 call assert_report('session must not restore teminal')
184 endif
185 endfor
186
187 call Stop_shell_in_terminal(bufnr('%'))
188 call delete('Xtest_mks.out')
189endfunc
190
191func Test_mksession_terminal_no_restore_funcarg()
192 call term_start(&shell, {'norestore': 1})
193 mksession! Xtest_mks.out
194 let lines = readfile('Xtest_mks.out')
195 let term_cmd = ''
196 for line in lines
197 if line =~ '^terminal'
198 call assert_report('session must not restore teminal')
199 endif
200 endfor
201
202 call Stop_shell_in_terminal(bufnr('%'))
203 call delete('Xtest_mks.out')
204endfunc
205
206func Test_mksession_terminal_no_restore_func()
207 terminal
208 call term_setrestore(bufnr('%'), 'NONE')
209 mksession! Xtest_mks.out
210 let lines = readfile('Xtest_mks.out')
211 let term_cmd = ''
212 for line in lines
213 if line =~ '^terminal'
214 call assert_report('session must not restore teminal')
215 endif
216 endfor
217
218 call Stop_shell_in_terminal(bufnr('%'))
219 call delete('Xtest_mks.out')
220endfunc
221
222func Test_mksession_terminal_no_ssop()
223 terminal
224 set sessionoptions-=terminal
225 mksession! Xtest_mks.out
226 let lines = readfile('Xtest_mks.out')
227 let term_cmd = ''
228 for line in lines
229 if line =~ '^terminal'
230 call assert_report('session must not restore teminal')
231 endif
232 endfor
233
234 call Stop_shell_in_terminal(bufnr('%'))
235 call delete('Xtest_mks.out')
236 set sessionoptions&
237endfunc
238
239func Test_mksession_terminal_restore_other()
240 terminal
241 call term_setrestore(bufnr('%'), 'other')
242 mksession! Xtest_mks.out
243 let lines = readfile('Xtest_mks.out')
244 let term_cmd = ''
245 for line in lines
246 if line =~ '^terminal'
247 let term_cmd = line
248 endif
249 endfor
250 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+ other', term_cmd)
251
252 call Stop_shell_in_terminal(bufnr('%'))
253 call delete('Xtest_mks.out')
254endfunc
255
256endif " has('terminal')
Bram Moolenaar4bebc9a2017-08-30 21:07:38 +0200257
Bram Moolenaar79da5632017-02-01 22:52:44 +0100258
Bram Moolenaareca626f2016-12-01 18:47:38 +0100259" vim: shiftwidth=2 sts=2 expandtab