Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 1 | " Test for :mksession, :mkview and :loadview in latin1 encoding |
| 2 | |
| 3 | set encoding=latin1 |
| 4 | scriptencoding latin1 |
| 5 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 6 | source check.vim |
| 7 | CheckFeature mksession |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 8 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 9 | source shared.vim |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 10 | source term_util.vim |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 11 | |
Bram Moolenaar | 1e15e61 | 2019-11-09 17:18:52 +0100 | [diff] [blame] | 12 | " Test for storing global and local argument list in a session file |
| 13 | " This one must be done first. |
| 14 | func 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') |
| 33 | endfunc |
| 34 | |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 35 | func 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 Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 48 | \ 'Aäöü three mulTibyte characters', |
| 49 | \ 'short line', |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 50 | \ ]) |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 51 | let tmpfile = 'Xtemp' |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 52 | 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 Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 71 | split |
| 72 | norm! j$ |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 73 | 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 Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 94 | mksession! Xtest_mks.out |
Bram Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 95 | let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"') |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 96 | 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 Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 105 | \ 'normal! $', |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 106 | \ " 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 Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 128 | call delete('Xtest_mks.out') |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 129 | call delete(tmpfile) |
| 130 | let &wrap = wrap_save |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 131 | set sessionoptions& |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 132 | endfunc |
| 133 | |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 134 | func Test_mksession_winheight() |
| 135 | new |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 136 | set winheight=10 |
| 137 | set winminheight=2 |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 138 | mksession! Xtest_mks.out |
| 139 | source Xtest_mks.out |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 140 | |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 141 | call delete('Xtest_mks.out') |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 142 | endfunc |
| 143 | |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 144 | func 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') |
| 150 | endfunc |
| 151 | |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 152 | func Test_mksession_rtp() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 153 | " TODO: fix problem with backslashes on Win32 |
| 154 | CheckNotMSWindows |
| 155 | |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 156 | new |
| 157 | let _rtp=&rtp |
| 158 | " Make a real long (invalid) runtimepath value, |
| 159 | " that should exceed PATH_MAX (hopefully) |
| 160 | let newrtp=&rtp.',~'.repeat('/foobar', 1000) |
| 161 | let newrtp.=",".expand("$HOME")."/.vim" |
| 162 | let &rtp=newrtp |
| 163 | |
| 164 | " determine expected value |
| 165 | let expected=split(&rtp, ',') |
| 166 | let expected = map(expected, '"set runtimepath+=".v:val') |
| 167 | let expected = ['set runtimepath='] + expected |
| 168 | let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")}) |
| 169 | |
| 170 | mksession! Xtest_mks.out |
| 171 | let &rtp=_rtp |
| 172 | let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"') |
| 173 | call assert_equal(expected, li) |
| 174 | |
| 175 | call delete('Xtest_mks.out') |
| 176 | endfunc |
| 177 | |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 178 | func Test_mksession_arglist() |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 179 | %argdel |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 180 | next file1 file2 file3 file4 |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 181 | new |
| 182 | next | next |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 183 | mksession! Xtest_mks.out |
| 184 | source Xtest_mks.out |
| 185 | call assert_equal(['file1', 'file2', 'file3', 'file4'], argv()) |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 186 | call assert_equal(2, argidx()) |
| 187 | wincmd w |
| 188 | call assert_equal(0, argidx()) |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 189 | |
| 190 | call delete('Xtest_mks.out') |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 191 | enew | only |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 192 | argdel * |
| 193 | endfunc |
| 194 | |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 195 | func Test_mksession_one_buffer_two_windows() |
| 196 | edit Xtest1 |
| 197 | new Xtest2 |
| 198 | split |
| 199 | mksession! Xtest_mks.out |
| 200 | let lines = readfile('Xtest_mks.out') |
| 201 | let count1 = 0 |
| 202 | let count2 = 0 |
| 203 | let count2buf = 0 |
| 204 | for line in lines |
| 205 | if line =~ 'edit \f*Xtest1$' |
| 206 | let count1 += 1 |
| 207 | endif |
| 208 | if line =~ 'edit \f\{-}Xtest2' |
| 209 | let count2 += 1 |
| 210 | endif |
| 211 | if line =~ 'buffer \f\{-}Xtest2' |
| 212 | let count2buf += 1 |
| 213 | endif |
| 214 | endfor |
| 215 | call assert_equal(1, count1, 'Xtest1 count') |
| 216 | call assert_equal(2, count2, 'Xtest2 count') |
| 217 | call assert_equal(2, count2buf, 'Xtest2 buffer count') |
| 218 | |
| 219 | close |
| 220 | bwipe! |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 221 | call delete('Xtest_mks.out') |
| 222 | endfunc |
| 223 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 224 | func Test_mksession_lcd_multiple_tabs() |
| 225 | tabnew |
| 226 | tabnew |
Bram Moolenaar | 81e2ac7 | 2018-07-04 22:44:08 +0200 | [diff] [blame] | 227 | lcd . |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 228 | tabfirst |
Bram Moolenaar | 81e2ac7 | 2018-07-04 22:44:08 +0200 | [diff] [blame] | 229 | lcd . |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 230 | mksession! Xtest_mks.out |
| 231 | tabonly |
| 232 | source Xtest_mks.out |
| 233 | call assert_true(haslocaldir(), 'Tab 1 localdir') |
| 234 | tabnext 2 |
| 235 | call assert_true(!haslocaldir(), 'Tab 2 localdir') |
| 236 | tabnext 3 |
| 237 | call assert_true(haslocaldir(), 'Tab 3 localdir') |
| 238 | call delete('Xtest_mks.out') |
| 239 | endfunc |
| 240 | |
Bram Moolenaar | 00aa069 | 2019-04-27 20:37:57 +0200 | [diff] [blame] | 241 | " Test for tabpage-local directory |
| 242 | func Test_mksession_tcd_multiple_tabs() |
| 243 | let save_cwd = getcwd() |
| 244 | call mkdir('Xtopdir') |
| 245 | cd Xtopdir |
| 246 | call mkdir('Xtabdir1') |
| 247 | call mkdir('Xtabdir2') |
| 248 | call mkdir('Xtabdir3') |
| 249 | call mkdir('Xwindir1') |
| 250 | call mkdir('Xwindir2') |
| 251 | call mkdir('Xwindir3') |
| 252 | tcd Xtabdir1 |
| 253 | botright new |
| 254 | wincmd t |
| 255 | lcd ../Xwindir1 |
| 256 | tabnew |
| 257 | tcd ../Xtabdir2 |
| 258 | botright new |
| 259 | lcd ../Xwindir2 |
| 260 | tabnew |
| 261 | tcd ../Xtabdir3 |
| 262 | botright new |
| 263 | lcd ../Xwindir3 |
| 264 | tabfirst |
| 265 | 1wincmd w |
| 266 | mksession! Xtest_mks.out |
| 267 | only | tabonly |
| 268 | source Xtest_mks.out |
| 269 | call assert_equal('Xtabdir1', fnamemodify(getcwd(-1, 1), ':t')) |
| 270 | call assert_equal('Xwindir1', fnamemodify(getcwd(1, 1), ':t')) |
| 271 | call assert_equal('Xtabdir1', fnamemodify(getcwd(2, 1), ':t')) |
| 272 | call assert_equal('Xtabdir2', fnamemodify(getcwd(-1, 2), ':t')) |
| 273 | call assert_equal('Xtabdir2', fnamemodify(getcwd(1, 2), ':t')) |
| 274 | call assert_equal('Xwindir2', fnamemodify(getcwd(2, 2), ':t')) |
| 275 | call assert_equal('Xtabdir3', fnamemodify(getcwd(-1, 3), ':t')) |
| 276 | call assert_equal('Xtabdir3', fnamemodify(getcwd(1, 3), ':t')) |
| 277 | call assert_equal('Xwindir3', fnamemodify(getcwd(2, 3), ':t')) |
Bram Moolenaar | 5bf46e9 | 2019-11-09 18:06:04 +0100 | [diff] [blame] | 278 | %bwipe |
| 279 | call chdir(save_cwd) |
Bram Moolenaar | 00aa069 | 2019-04-27 20:37:57 +0200 | [diff] [blame] | 280 | call delete("Xtopdir", "rf") |
| 281 | endfunc |
| 282 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 283 | func Test_mksession_blank_tabs() |
| 284 | tabnew |
| 285 | tabnew |
| 286 | tabnew |
| 287 | tabnext 3 |
| 288 | mksession! Xtest_mks.out |
| 289 | tabnew |
| 290 | tabnew |
| 291 | tabnext 2 |
| 292 | source Xtest_mks.out |
| 293 | call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs') |
| 294 | call assert_equal(3, tabpagenr(), 'session restore should restore the active tab') |
| 295 | call delete('Xtest_mks.out') |
| 296 | endfunc |
| 297 | |
Bram Moolenaar | d39e275 | 2019-01-26 20:07:38 +0100 | [diff] [blame] | 298 | func Test_mksession_buffer_count() |
| 299 | set hidden |
| 300 | |
| 301 | " Edit exactly three files in the current session. |
| 302 | %bwipe! |
| 303 | e Xfoo | tabe Xbar | tabe Xbaz |
| 304 | tabdo write |
| 305 | mksession! Xtest_mks.out |
| 306 | |
| 307 | " Verify that loading the session does not create additional buffers. |
| 308 | %bwipe! |
| 309 | source Xtest_mks.out |
| 310 | call assert_equal(3, len(getbufinfo())) |
| 311 | |
| 312 | " Clean up. |
| 313 | call delete('Xfoo') |
| 314 | call delete('Xbar') |
| 315 | call delete('Xbaz') |
| 316 | call delete('Xtest_mks.out') |
| 317 | %bwipe! |
| 318 | set hidden& |
| 319 | endfunc |
| 320 | |
Bram Moolenaar | e3c74d2 | 2019-01-12 16:29:30 +0100 | [diff] [blame] | 321 | if has('extra_search') |
| 322 | |
| 323 | func Test_mksession_hlsearch() |
| 324 | set hlsearch |
| 325 | mksession! Xtest_mks.out |
| 326 | nohlsearch |
| 327 | source Xtest_mks.out |
| 328 | call assert_equal(1, v:hlsearch, 'session should restore search highlighting state') |
| 329 | nohlsearch |
| 330 | mksession! Xtest_mks.out |
| 331 | source Xtest_mks.out |
| 332 | call assert_equal(0, v:hlsearch, 'session should restore search highlighting state') |
| 333 | call delete('Xtest_mks.out') |
| 334 | endfunc |
| 335 | |
| 336 | endif |
| 337 | |
| 338 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 339 | func Test_mksession_blank_windows() |
| 340 | split |
| 341 | split |
| 342 | split |
| 343 | 3 wincmd w |
| 344 | mksession! Xtest_mks.out |
| 345 | split |
| 346 | split |
| 347 | 2 wincmd w |
| 348 | source Xtest_mks.out |
| 349 | call assert_equal(4, winnr('$'), 'session restore should restore number of windows') |
| 350 | call assert_equal(3, winnr(), 'session restore should restore the active window') |
| 351 | call delete('Xtest_mks.out') |
| 352 | endfunc |
| 353 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 354 | func Test_mksession_terminal_shell() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 355 | CheckFeature terminal |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 356 | CheckFeature quickfix |
| 357 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 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 Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 369 | call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 370 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 371 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 372 | call delete('Xtest_mks.out') |
| 373 | endfunc |
| 374 | |
| 375 | func Test_mksession_terminal_no_restore_cmdarg() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 376 | CheckFeature terminal |
| 377 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 378 | terminal ++norestore |
| 379 | mksession! Xtest_mks.out |
| 380 | let lines = readfile('Xtest_mks.out') |
| 381 | let term_cmd = '' |
| 382 | for line in lines |
| 383 | if line =~ '^terminal' |
| 384 | call assert_report('session must not restore teminal') |
| 385 | endif |
| 386 | endfor |
| 387 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 388 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 389 | call delete('Xtest_mks.out') |
| 390 | endfunc |
| 391 | |
| 392 | func Test_mksession_terminal_no_restore_funcarg() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 393 | CheckFeature terminal |
| 394 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 395 | call term_start(&shell, {'norestore': 1}) |
| 396 | mksession! Xtest_mks.out |
| 397 | let lines = readfile('Xtest_mks.out') |
| 398 | let term_cmd = '' |
| 399 | for line in lines |
| 400 | if line =~ '^terminal' |
| 401 | call assert_report('session must not restore teminal') |
| 402 | endif |
| 403 | endfor |
| 404 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 405 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 406 | call delete('Xtest_mks.out') |
| 407 | endfunc |
| 408 | |
| 409 | func Test_mksession_terminal_no_restore_func() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 410 | CheckFeature terminal |
| 411 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 412 | terminal |
| 413 | call term_setrestore(bufnr('%'), 'NONE') |
| 414 | mksession! Xtest_mks.out |
| 415 | let lines = readfile('Xtest_mks.out') |
| 416 | let term_cmd = '' |
| 417 | for line in lines |
| 418 | if line =~ '^terminal' |
| 419 | call assert_report('session must not restore teminal') |
| 420 | endif |
| 421 | endfor |
| 422 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 423 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 424 | call delete('Xtest_mks.out') |
| 425 | endfunc |
| 426 | |
| 427 | func Test_mksession_terminal_no_ssop() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 428 | CheckFeature terminal |
| 429 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 430 | terminal |
| 431 | set sessionoptions-=terminal |
| 432 | mksession! Xtest_mks.out |
| 433 | let lines = readfile('Xtest_mks.out') |
| 434 | let term_cmd = '' |
| 435 | for line in lines |
| 436 | if line =~ '^terminal' |
| 437 | call assert_report('session must not restore teminal') |
| 438 | endif |
| 439 | endfor |
| 440 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 441 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 442 | call delete('Xtest_mks.out') |
| 443 | set sessionoptions& |
| 444 | endfunc |
| 445 | |
| 446 | func Test_mksession_terminal_restore_other() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 447 | CheckFeature terminal |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 448 | CheckFeature quickfix |
| 449 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 450 | terminal |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 451 | eval bufnr('%')->term_setrestore('other') |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 452 | mksession! Xtest_mks.out |
| 453 | let lines = readfile('Xtest_mks.out') |
| 454 | let term_cmd = '' |
| 455 | for line in lines |
| 456 | if line =~ '^terminal' |
| 457 | let term_cmd = line |
| 458 | endif |
| 459 | endfor |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 460 | call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 461 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 462 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 463 | call delete('Xtest_mks.out') |
| 464 | endfunc |
| 465 | |
Bram Moolenaar | 0e65511 | 2020-09-11 20:36:36 +0200 | [diff] [blame] | 466 | func Test_mksession_terminal_shared_windows() |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 467 | CheckFeature terminal |
| 468 | |
Bram Moolenaar | 0e65511 | 2020-09-11 20:36:36 +0200 | [diff] [blame] | 469 | terminal |
| 470 | let term_buf = bufnr() |
| 471 | new |
| 472 | execute "buffer" term_buf |
| 473 | mksession! Xtest_mks.out |
| 474 | |
| 475 | let lines = readfile('Xtest_mks.out') |
| 476 | let found_creation = 0 |
| 477 | let found_use = 0 |
| 478 | |
| 479 | for line in lines |
| 480 | if line =~ '^terminal' |
| 481 | let found_creation = 1 |
| 482 | call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+', line) |
| 483 | elseif line =~ "^execute 'buffer ' . s:term_buf_" . term_buf . "$" |
| 484 | let found_use = 1 |
| 485 | endif |
| 486 | endfor |
| 487 | |
| 488 | call assert_true(found_creation && found_use) |
| 489 | |
| 490 | call StopShellInTerminal(term_buf) |
| 491 | call delete('Xtest_mks.out') |
| 492 | endfunc |
| 493 | |
Bram Moolenaar | c2c8205 | 2020-09-11 22:10:22 +0200 | [diff] [blame] | 494 | func Test_mkview_terminal_windows() |
| 495 | CheckFeature terminal |
| 496 | |
| 497 | " create two window on the same terminal to check this is handled OK |
| 498 | terminal |
| 499 | let term_buf = bufnr() |
| 500 | exe 'sbuf ' .. term_buf |
| 501 | mkview! Xtestview |
| 502 | |
| 503 | call StopShellInTerminal(term_buf) |
| 504 | call delete('Xtestview') |
| 505 | endfunc |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 506 | |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 507 | " Test :mkview with a file argument. |
| 508 | func Test_mkview_file() |
| 509 | " Create a view with line number and a fold. |
| 510 | help :mkview |
| 511 | set number |
Bram Moolenaar | 2bf4fe0 | 2018-08-30 14:04:25 +0200 | [diff] [blame] | 512 | norm! V}zf0 |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 513 | let pos = getpos('.') |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 514 | let linefoldclosed1 = foldclosed('.') |
| 515 | mkview! Xview |
| 516 | set nonumber |
| 517 | norm! zrj |
| 518 | " We can close the help window, as mkview with a file name should |
| 519 | " generate a command to edit the file. |
| 520 | helpclose |
| 521 | |
| 522 | source Xview |
| 523 | call assert_equal(1, &number) |
| 524 | call assert_match('\*:mkview\*$', getline('.')) |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 525 | call assert_equal(pos, getpos('.')) |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 526 | call assert_equal(linefoldclosed1, foldclosed('.')) |
| 527 | |
| 528 | " Creating a view again with the same file name should fail (file |
| 529 | " already exists). But with a !, the previous view should be |
| 530 | " overwritten without error. |
| 531 | help :loadview |
| 532 | call assert_fails('mkview Xview', 'E189:') |
| 533 | call assert_match('\*:loadview\*$', getline('.')) |
| 534 | mkview! Xview |
| 535 | call assert_match('\*:loadview\*$', getline('.')) |
| 536 | |
| 537 | call delete('Xview') |
| 538 | bwipe |
| 539 | endfunc |
| 540 | |
| 541 | " Test :mkview and :loadview with a custom 'viewdir'. |
| 542 | func Test_mkview_loadview_with_viewdir() |
| 543 | set viewdir=Xviewdir |
| 544 | |
| 545 | help :mkview |
| 546 | set number |
| 547 | norm! V}zf |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 548 | let pos = getpos('.') |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 549 | let linefoldclosed1 = foldclosed('.') |
| 550 | mkview 1 |
| 551 | set nonumber |
| 552 | norm! zrj |
| 553 | |
| 554 | loadview 1 |
| 555 | |
| 556 | " The directory Xviewdir/ should have been created and the view |
| 557 | " should be stored in that directory. |
| 558 | call assert_equal('Xviewdir/' . |
| 559 | \ substitute( |
| 560 | \ substitute( |
| 561 | \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', |
| 562 | \ glob('Xviewdir/*')) |
| 563 | call assert_equal(1, &number) |
| 564 | call assert_match('\*:mkview\*$', getline('.')) |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 565 | call assert_equal(pos, getpos('.')) |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 566 | call assert_equal(linefoldclosed1, foldclosed('.')) |
| 567 | |
| 568 | call delete('Xviewdir', 'rf') |
| 569 | set viewdir& |
| 570 | helpclose |
| 571 | endfunc |
| 572 | |
| 573 | func Test_mkview_no_file_name() |
| 574 | new |
| 575 | " :mkview or :mkview {nr} should fail in a unnamed buffer. |
| 576 | call assert_fails('mkview', 'E32:') |
| 577 | call assert_fails('mkview 1', 'E32:') |
| 578 | |
| 579 | " :mkview {file} should succeed in a unnamed buffer. |
| 580 | mkview Xview |
| 581 | help |
| 582 | source Xview |
| 583 | call assert_equal('', bufname('%')) |
| 584 | |
| 585 | call delete('Xview') |
| 586 | %bwipe |
| 587 | endfunc |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 588 | |
Bram Moolenaar | 3482be6 | 2020-11-27 11:00:38 +0100 | [diff] [blame^] | 589 | func Test_mkview_loadview_jumplist() |
| 590 | set viewdir=Xviewdir |
| 591 | au BufWinLeave * silent mkview |
| 592 | au BufWinEnter * silent loadview |
| 593 | |
| 594 | edit Xfile1 |
| 595 | call setline(1, ['a', 'bbbbbbb', 'c']) |
| 596 | normal j3l |
| 597 | call assert_equal([2, 4], getcurpos()[1:2]) |
| 598 | write |
| 599 | |
| 600 | edit Xfile2 |
| 601 | call setline(1, ['d', 'eeeeeee', 'f']) |
| 602 | normal j5l |
| 603 | call assert_equal([2, 6], getcurpos()[1:2]) |
| 604 | write |
| 605 | |
| 606 | edit Xfile3 |
| 607 | call setline(1, ['g', 'h', 'iiiii']) |
| 608 | normal jj3l |
| 609 | call assert_equal([3, 4], getcurpos()[1:2]) |
| 610 | write |
| 611 | |
| 612 | edit Xfile1 |
| 613 | call assert_equal([2, 4], getcurpos()[1:2]) |
| 614 | edit Xfile2 |
| 615 | call assert_equal([2, 6], getcurpos()[1:2]) |
| 616 | edit Xfile3 |
| 617 | call assert_equal([3, 4], getcurpos()[1:2]) |
| 618 | |
| 619 | exe "normal \<C-O>" |
| 620 | call assert_equal('Xfile2', expand('%')) |
| 621 | call assert_equal([2, 6], getcurpos()[1:2]) |
| 622 | exe "normal \<C-O>" |
| 623 | call assert_equal('Xfile1', expand('%')) |
| 624 | call assert_equal([2, 4], getcurpos()[1:2]) |
| 625 | |
| 626 | au! BufWinLeave |
| 627 | au! BufWinEnter |
| 628 | bwipe! |
| 629 | call delete('Xviewdir', 'rf') |
| 630 | call delete('Xfile1') |
| 631 | call delete('Xfile2') |
| 632 | call delete('Xfile3') |
| 633 | set viewdir& |
| 634 | endfunc |
| 635 | |
Bram Moolenaar | 555de4e | 2019-01-21 23:03:49 +0100 | [diff] [blame] | 636 | " A clean session (one empty buffer, one window, and one tab) should not |
| 637 | " set any error messages when sourced because no commands should fail. |
| 638 | func Test_mksession_no_errmsg() |
| 639 | let v:errmsg = '' |
| 640 | %bwipe! |
| 641 | mksession! Xtest_mks.out |
| 642 | source Xtest_mks.out |
| 643 | call assert_equal('', v:errmsg) |
| 644 | call delete('Xtest_mks.out') |
| 645 | endfunc |
| 646 | |
Bram Moolenaar | ad36a35 | 2019-01-24 13:34:42 +0100 | [diff] [blame] | 647 | func Test_mksession_quote_in_filename() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 648 | " only Unix can handle this weird filename |
| 649 | CheckUnix |
| 650 | |
Bram Moolenaar | ad36a35 | 2019-01-24 13:34:42 +0100 | [diff] [blame] | 651 | let v:errmsg = '' |
| 652 | %bwipe! |
| 653 | split another |
| 654 | split x'y\"z |
| 655 | mksession! Xtest_mks_quoted.out |
| 656 | %bwipe! |
| 657 | source Xtest_mks_quoted.out |
| 658 | call assert_true(bufexists("x'y\"z")) |
| 659 | |
| 660 | %bwipe! |
| 661 | call delete('Xtest_mks_quoted.out') |
| 662 | endfunc |
| 663 | |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 664 | " Test for storing global variables in a session file |
| 665 | func Test_mksession_globals() |
| 666 | set sessionoptions+=globals |
| 667 | |
| 668 | " create different global variables |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 669 | let g:Global_string = "Sun is shining\r\n" |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 670 | let g:Global_count = 100 |
| 671 | let g:Global_pi = 3.14 |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 672 | let g:Global_neg_float = -2.68 |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 673 | |
| 674 | mksession! Xtest_mks.out |
| 675 | |
| 676 | unlet g:Global_string |
| 677 | unlet g:Global_count |
| 678 | unlet g:Global_pi |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 679 | unlet g:Global_neg_float |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 680 | |
| 681 | source Xtest_mks.out |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 682 | call assert_equal("Sun is shining\r\n", g:Global_string) |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 683 | call assert_equal(100, g:Global_count) |
| 684 | call assert_equal(3.14, g:Global_pi) |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 685 | call assert_equal(-2.68, g:Global_neg_float) |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 686 | |
| 687 | unlet g:Global_string |
| 688 | unlet g:Global_count |
| 689 | unlet g:Global_pi |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 690 | unlet g:Global_neg_float |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 691 | call delete('Xtest_mks.out') |
| 692 | set sessionoptions& |
| 693 | endfunc |
| 694 | |
| 695 | " Test for changing backslash to forward slash in filenames |
| 696 | func Test_mksession_slash() |
Bram Moolenaar | 37ac4a5 | 2019-09-28 19:29:04 +0200 | [diff] [blame] | 697 | if exists('+shellslash') |
| 698 | throw 'Skipped: cannot use backslash in file name' |
| 699 | endif |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 700 | enew |
| 701 | %bwipe! |
| 702 | e a\\b\\c |
| 703 | mksession! Xtest_mks1.out |
| 704 | set sessionoptions+=slash |
| 705 | mksession! Xtest_mks2.out |
| 706 | |
| 707 | %bwipe! |
| 708 | source Xtest_mks1.out |
| 709 | call assert_equal('a\b\c', bufname('')) |
| 710 | %bwipe! |
| 711 | source Xtest_mks2.out |
| 712 | call assert_equal('a/b/c', bufname('')) |
| 713 | |
| 714 | %bwipe! |
| 715 | call delete('Xtest_mks1.out') |
| 716 | call delete('Xtest_mks2.out') |
| 717 | set sessionoptions& |
| 718 | endfunc |
| 719 | |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 720 | " Test for changing directory to the session file directory |
| 721 | func Test_mksession_sesdir() |
Bram Moolenaar | 5bf46e9 | 2019-11-09 18:06:04 +0100 | [diff] [blame] | 722 | let save_cwd = getcwd() |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 723 | call mkdir('Xproj') |
| 724 | mksession! Xproj/Xtest_mks1.out |
| 725 | set sessionoptions-=curdir |
| 726 | set sessionoptions+=sesdir |
| 727 | mksession! Xproj/Xtest_mks2.out |
| 728 | |
| 729 | source Xproj/Xtest_mks1.out |
| 730 | call assert_equal('testdir', fnamemodify(getcwd(), ':t')) |
| 731 | source Xproj/Xtest_mks2.out |
| 732 | call assert_equal('Xproj', fnamemodify(getcwd(), ':t')) |
Bram Moolenaar | 5bf46e9 | 2019-11-09 18:06:04 +0100 | [diff] [blame] | 733 | call chdir(save_cwd) |
| 734 | %bwipe |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 735 | |
| 736 | set sessionoptions& |
| 737 | call delete('Xproj', 'rf') |
| 738 | endfunc |
| 739 | |
| 740 | " Test for storing the 'lines' and 'columns' settings |
| 741 | func Test_mksession_resize() |
| 742 | mksession! Xtest_mks1.out |
| 743 | set sessionoptions+=resize |
| 744 | mksession! Xtest_mks2.out |
| 745 | |
| 746 | let lines = readfile('Xtest_mks1.out') |
| 747 | let found_resize = v:false |
| 748 | for line in lines |
| 749 | if line =~ '^set lines=' |
| 750 | let found_resize = v:true |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 751 | break |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 752 | endif |
| 753 | endfor |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 754 | call assert_false(found_resize) |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 755 | let lines = readfile('Xtest_mks2.out') |
| 756 | let found_resize = v:false |
| 757 | for line in lines |
| 758 | if line =~ '^set lines=' |
| 759 | let found_resize = v:true |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 760 | break |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 761 | endif |
| 762 | endfor |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 763 | call assert_true(found_resize) |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame] | 764 | |
| 765 | call delete('Xtest_mks1.out') |
| 766 | call delete('Xtest_mks2.out') |
| 767 | set sessionoptions& |
| 768 | endfunc |
| 769 | |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 770 | " Test for mksession with a named scratch buffer |
| 771 | func Test_mksession_scratch() |
| 772 | enew | only |
| 773 | file Xscratch |
| 774 | set buftype=nofile |
| 775 | mksession! Xtest_mks.out |
| 776 | %bwipe |
| 777 | source Xtest_mks.out |
| 778 | call assert_equal('Xscratch', bufname('')) |
| 779 | call assert_equal('nofile', &buftype) |
| 780 | %bwipe |
| 781 | call delete('Xtest_mks.out') |
| 782 | endfunc |
| 783 | |
| 784 | " Test for mksession with fold options |
| 785 | func Test_mksession_foldopt() |
| 786 | set sessionoptions-=options |
| 787 | set sessionoptions+=folds |
| 788 | new |
| 789 | setlocal foldenable |
| 790 | setlocal foldmethod=expr |
| 791 | setlocal foldmarker=<<<,>>> |
| 792 | setlocal foldignore=% |
| 793 | setlocal foldlevel=2 |
| 794 | setlocal foldminlines=10 |
| 795 | setlocal foldnestmax=15 |
| 796 | mksession! Xtest_mks.out |
| 797 | close |
| 798 | %bwipe |
| 799 | |
| 800 | source Xtest_mks.out |
| 801 | call assert_true(&foldenable) |
| 802 | call assert_equal('expr', &foldmethod) |
| 803 | call assert_equal('<<<,>>>', &foldmarker) |
| 804 | call assert_equal('%', &foldignore) |
| 805 | call assert_equal(2, &foldlevel) |
| 806 | call assert_equal(10, &foldminlines) |
| 807 | call assert_equal(15, &foldnestmax) |
| 808 | |
| 809 | close |
| 810 | %bwipe |
| 811 | set sessionoptions& |
| 812 | endfunc |
| 813 | |
| 814 | " Test for mksession with window position |
| 815 | func Test_mksession_winpos() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 816 | " Only applicable in GUI Vim |
| 817 | CheckGui |
| 818 | |
Bram Moolenaar | ee1a2b5 | 2019-09-29 14:23:39 +0200 | [diff] [blame] | 819 | set sessionoptions+=winpos |
| 820 | mksession! Xtest_mks.out |
| 821 | let found_winpos = v:false |
| 822 | let lines = readfile('Xtest_mks.out') |
| 823 | for line in lines |
| 824 | if line =~ '^winpos ' |
| 825 | let found_winpos = v:true |
| 826 | break |
| 827 | endif |
| 828 | endfor |
| 829 | call assert_true(found_winpos) |
| 830 | call delete('Xtest_mks.out') |
| 831 | set sessionoptions& |
| 832 | endfunc |
| 833 | |
| 834 | " Test for mksession with 'compatible' option |
| 835 | func Test_mksession_compatible() |
| 836 | mksession! Xtest_mks1.out |
| 837 | set compatible |
| 838 | mksession! Xtest_mks2.out |
| 839 | set nocp |
| 840 | |
| 841 | let test_success = v:false |
| 842 | let lines = readfile('Xtest_mks1.out') |
| 843 | for line in lines |
| 844 | if line =~ '^if &cp | set nocp | endif' |
| 845 | let test_success = v:true |
| 846 | break |
| 847 | endif |
| 848 | endfor |
| 849 | call assert_true(test_success) |
| 850 | |
| 851 | let test_success = v:false |
| 852 | let lines = readfile('Xtest_mks2.out') |
| 853 | for line in lines |
| 854 | if line =~ '^if !&cp | set cp | endif' |
| 855 | let test_success = v:true |
| 856 | break |
| 857 | endif |
| 858 | endfor |
| 859 | call assert_true(test_success) |
| 860 | |
| 861 | call delete('Xtest_mks1.out') |
| 862 | call delete('Xtest_mks2.out') |
| 863 | set compatible& |
| 864 | set sessionoptions& |
| 865 | endfunc |
| 866 | |
Bram Moolenaar | 8750026 | 2019-08-01 23:05:49 +0200 | [diff] [blame] | 867 | func s:ClearMappings() |
| 868 | mapclear |
| 869 | omapclear |
| 870 | mapclear! |
| 871 | lmapclear |
| 872 | tmapclear |
| 873 | endfunc |
| 874 | |
| 875 | func Test_mkvimrc() |
| 876 | let entries = [ |
| 877 | \ ['', 'nothing', '<Nop>'], |
| 878 | \ ['n', 'normal', 'NORMAL'], |
| 879 | \ ['v', 'visual', 'VISUAL'], |
| 880 | \ ['s', 'select', 'SELECT'], |
| 881 | \ ['x', 'visualonly', 'VISUALONLY'], |
| 882 | \ ['o', 'operator', 'OPERATOR'], |
| 883 | \ ['i', 'insert', 'INSERT'], |
| 884 | \ ['l', 'lang', 'LANG'], |
| 885 | \ ['c', 'command', 'COMMAND'], |
| 886 | \ ['t', 'terminal', 'TERMINAL'], |
| 887 | \ ] |
| 888 | for entry in entries |
| 889 | exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2] |
| 890 | endfor |
| 891 | |
| 892 | mkvimrc Xtestvimrc |
| 893 | |
| 894 | call s:ClearMappings() |
| 895 | for entry in entries |
| 896 | call assert_equal('', maparg(entry[1], entry[0])) |
| 897 | endfor |
| 898 | |
| 899 | source Xtestvimrc |
| 900 | |
| 901 | for entry in entries |
| 902 | call assert_equal(entry[2], maparg(entry[1], entry[0])) |
| 903 | endfor |
| 904 | |
| 905 | call s:ClearMappings() |
| 906 | call delete('Xtestvimrc') |
| 907 | endfunc |
| 908 | |
Bram Moolenaar | 3889083 | 2020-11-01 17:40:54 +0100 | [diff] [blame] | 909 | func Test_scrolloff() |
| 910 | set sessionoptions+=localoptions |
| 911 | setlocal so=1 siso=1 |
| 912 | mksession! Xtest_mks.out |
| 913 | setlocal so=-1 siso=-1 |
| 914 | source Xtest_mks.out |
| 915 | call assert_equal(1, &l:so) |
| 916 | call assert_equal(1, &l:siso) |
| 917 | call delete('Xtest_mks.out') |
| 918 | setlocal so& siso& |
| 919 | set sessionoptions& |
| 920 | endfunc |
| 921 | |
Bram Moolenaar | 3482be6 | 2020-11-27 11:00:38 +0100 | [diff] [blame^] | 922 | func Test_altfile() |
| 923 | edit Xone |
| 924 | split Xtwo |
| 925 | edit Xtwoalt |
| 926 | edit # |
| 927 | wincmd w |
| 928 | edit Xonealt |
| 929 | edit # |
| 930 | mksession! Xtest_altfile |
| 931 | only |
| 932 | bwipe Xonealt |
| 933 | bwipe Xtwoalt |
| 934 | bwipe! |
| 935 | source Xtest_altfile |
| 936 | call assert_equal('Xone', bufname()) |
| 937 | call assert_equal('Xonealt', bufname('#')) |
| 938 | wincmd w |
| 939 | call assert_equal('Xtwo', bufname()) |
| 940 | call assert_equal('Xtwoalt', bufname('#')) |
| 941 | only |
| 942 | bwipe! |
| 943 | endfunc |
| 944 | |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 945 | " vim: shiftwidth=2 sts=2 expandtab |