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 | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 12 | func 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', |
Bram Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 25 | \ 'Aäöü three mulTibyte characters', |
| 26 | \ 'short line', |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 27 | \ ]) |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 28 | let tmpfile = 'Xtemp' |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 29 | exec 'w! ' . tmpfile |
| 30 | /^start: |
| 31 | set wrap |
| 32 | vsplit |
| 33 | norm! j16| |
| 34 | split |
| 35 | norm! j16| |
| 36 | split |
| 37 | norm! j16| |
| 38 | split |
| 39 | norm! j8| |
| 40 | split |
| 41 | norm! j8| |
| 42 | split |
| 43 | norm! j16| |
| 44 | split |
| 45 | norm! j16| |
| 46 | split |
| 47 | norm! j16| |
Bram Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 48 | split |
| 49 | norm! j$ |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 50 | wincmd l |
| 51 | |
| 52 | set nowrap |
| 53 | /^start: |
| 54 | norm! j16|3zl |
| 55 | split |
| 56 | norm! j016|3zl |
| 57 | split |
| 58 | norm! j016|3zl |
| 59 | split |
| 60 | norm! j08|3zl |
| 61 | split |
| 62 | norm! j08|3zl |
| 63 | split |
| 64 | norm! j016|3zl |
| 65 | split |
| 66 | norm! j016|3zl |
| 67 | split |
| 68 | norm! j016|3zl |
| 69 | split |
| 70 | call wincol() |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 71 | mksession! Xtest_mks.out |
Bram Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 72 | 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] | 73 | let expected = [ |
| 74 | \ 'normal! 016|', |
| 75 | \ 'normal! 016|', |
| 76 | \ 'normal! 016|', |
| 77 | \ 'normal! 08|', |
| 78 | \ 'normal! 08|', |
| 79 | \ 'normal! 016|', |
| 80 | \ 'normal! 016|', |
| 81 | \ 'normal! 016|', |
Bram Moolenaar | 92c1b69 | 2018-08-29 21:42:42 +0200 | [diff] [blame] | 82 | \ 'normal! $', |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 83 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 84 | \ " normal! 016|", |
| 85 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 86 | \ " normal! 016|", |
| 87 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 88 | \ " normal! 016|", |
| 89 | \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", |
| 90 | \ " normal! 08|", |
| 91 | \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", |
| 92 | \ " normal! 08|", |
| 93 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 94 | \ " normal! 016|", |
| 95 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 96 | \ " normal! 016|", |
| 97 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 98 | \ " normal! 016|", |
| 99 | \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", |
| 100 | \ " normal! 016|" |
| 101 | \ ] |
| 102 | call assert_equal(expected, li) |
| 103 | tabclose! |
| 104 | |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 105 | call delete('Xtest_mks.out') |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 106 | call delete(tmpfile) |
| 107 | let &wrap = wrap_save |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 108 | set sessionoptions& |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 109 | endfunc |
| 110 | |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 111 | func Test_mksession_winheight() |
| 112 | new |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 113 | set winheight=10 |
| 114 | set winminheight=2 |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 115 | mksession! Xtest_mks.out |
| 116 | source Xtest_mks.out |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 117 | |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 118 | call delete('Xtest_mks.out') |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 119 | endfunc |
| 120 | |
Bram Moolenaar | 1c3c104 | 2018-06-12 16:49:30 +0200 | [diff] [blame] | 121 | func Test_mksession_large_winheight() |
| 122 | set winheight=999 |
| 123 | mksession! Xtest_mks_winheight.out |
| 124 | set winheight& |
| 125 | source Xtest_mks_winheight.out |
| 126 | call delete('Xtest_mks_winheight.out') |
| 127 | endfunc |
| 128 | |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 129 | func Test_mksession_rtp() |
Bram Moolenaar | 681b6bc | 2019-01-24 22:23:58 +0100 | [diff] [blame] | 130 | if has('win32') |
| 131 | " TODO: fix problem with backslashes |
| 132 | return |
| 133 | endif |
Bram Moolenaar | ed18f2c | 2019-01-24 20:30:52 +0100 | [diff] [blame] | 134 | new |
| 135 | let _rtp=&rtp |
| 136 | " Make a real long (invalid) runtimepath value, |
| 137 | " that should exceed PATH_MAX (hopefully) |
| 138 | let newrtp=&rtp.',~'.repeat('/foobar', 1000) |
| 139 | let newrtp.=",".expand("$HOME")."/.vim" |
| 140 | let &rtp=newrtp |
| 141 | |
| 142 | " determine expected value |
| 143 | let expected=split(&rtp, ',') |
| 144 | let expected = map(expected, '"set runtimepath+=".v:val') |
| 145 | let expected = ['set runtimepath='] + expected |
| 146 | let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")}) |
| 147 | |
| 148 | mksession! Xtest_mks.out |
| 149 | let &rtp=_rtp |
| 150 | let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"') |
| 151 | call assert_equal(expected, li) |
| 152 | |
| 153 | call delete('Xtest_mks.out') |
| 154 | endfunc |
| 155 | |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 156 | func Test_mksession_arglist() |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame^] | 157 | %argdel |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 158 | next file1 file2 file3 file4 |
| 159 | mksession! Xtest_mks.out |
| 160 | source Xtest_mks.out |
| 161 | call assert_equal(['file1', 'file2', 'file3', 'file4'], argv()) |
| 162 | |
| 163 | call delete('Xtest_mks.out') |
| 164 | argdel * |
| 165 | endfunc |
| 166 | |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 167 | func Test_mksession_one_buffer_two_windows() |
| 168 | edit Xtest1 |
| 169 | new Xtest2 |
| 170 | split |
| 171 | mksession! Xtest_mks.out |
| 172 | let lines = readfile('Xtest_mks.out') |
| 173 | let count1 = 0 |
| 174 | let count2 = 0 |
| 175 | let count2buf = 0 |
| 176 | for line in lines |
| 177 | if line =~ 'edit \f*Xtest1$' |
| 178 | let count1 += 1 |
| 179 | endif |
| 180 | if line =~ 'edit \f\{-}Xtest2' |
| 181 | let count2 += 1 |
| 182 | endif |
| 183 | if line =~ 'buffer \f\{-}Xtest2' |
| 184 | let count2buf += 1 |
| 185 | endif |
| 186 | endfor |
| 187 | call assert_equal(1, count1, 'Xtest1 count') |
| 188 | call assert_equal(2, count2, 'Xtest2 count') |
| 189 | call assert_equal(2, count2buf, 'Xtest2 buffer count') |
| 190 | |
| 191 | close |
| 192 | bwipe! |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 193 | call delete('Xtest_mks.out') |
| 194 | endfunc |
| 195 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 196 | func Test_mksession_lcd_multiple_tabs() |
| 197 | tabnew |
| 198 | tabnew |
Bram Moolenaar | 81e2ac7 | 2018-07-04 22:44:08 +0200 | [diff] [blame] | 199 | lcd . |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 200 | tabfirst |
Bram Moolenaar | 81e2ac7 | 2018-07-04 22:44:08 +0200 | [diff] [blame] | 201 | lcd . |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 202 | mksession! Xtest_mks.out |
| 203 | tabonly |
| 204 | source Xtest_mks.out |
| 205 | call assert_true(haslocaldir(), 'Tab 1 localdir') |
| 206 | tabnext 2 |
| 207 | call assert_true(!haslocaldir(), 'Tab 2 localdir') |
| 208 | tabnext 3 |
| 209 | call assert_true(haslocaldir(), 'Tab 3 localdir') |
| 210 | call delete('Xtest_mks.out') |
| 211 | endfunc |
| 212 | |
Bram Moolenaar | 00aa069 | 2019-04-27 20:37:57 +0200 | [diff] [blame] | 213 | " Test for tabpage-local directory |
| 214 | func Test_mksession_tcd_multiple_tabs() |
| 215 | let save_cwd = getcwd() |
| 216 | call mkdir('Xtopdir') |
| 217 | cd Xtopdir |
| 218 | call mkdir('Xtabdir1') |
| 219 | call mkdir('Xtabdir2') |
| 220 | call mkdir('Xtabdir3') |
| 221 | call mkdir('Xwindir1') |
| 222 | call mkdir('Xwindir2') |
| 223 | call mkdir('Xwindir3') |
| 224 | tcd Xtabdir1 |
| 225 | botright new |
| 226 | wincmd t |
| 227 | lcd ../Xwindir1 |
| 228 | tabnew |
| 229 | tcd ../Xtabdir2 |
| 230 | botright new |
| 231 | lcd ../Xwindir2 |
| 232 | tabnew |
| 233 | tcd ../Xtabdir3 |
| 234 | botright new |
| 235 | lcd ../Xwindir3 |
| 236 | tabfirst |
| 237 | 1wincmd w |
| 238 | mksession! Xtest_mks.out |
| 239 | only | tabonly |
| 240 | source Xtest_mks.out |
| 241 | call assert_equal('Xtabdir1', fnamemodify(getcwd(-1, 1), ':t')) |
| 242 | call assert_equal('Xwindir1', fnamemodify(getcwd(1, 1), ':t')) |
| 243 | call assert_equal('Xtabdir1', fnamemodify(getcwd(2, 1), ':t')) |
| 244 | call assert_equal('Xtabdir2', fnamemodify(getcwd(-1, 2), ':t')) |
| 245 | call assert_equal('Xtabdir2', fnamemodify(getcwd(1, 2), ':t')) |
| 246 | call assert_equal('Xwindir2', fnamemodify(getcwd(2, 2), ':t')) |
| 247 | call assert_equal('Xtabdir3', fnamemodify(getcwd(-1, 3), ':t')) |
| 248 | call assert_equal('Xtabdir3', fnamemodify(getcwd(1, 3), ':t')) |
| 249 | call assert_equal('Xwindir3', fnamemodify(getcwd(2, 3), ':t')) |
| 250 | only | tabonly |
| 251 | exe 'cd ' . save_cwd |
| 252 | call delete("Xtopdir", "rf") |
| 253 | endfunc |
| 254 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 255 | func Test_mksession_blank_tabs() |
| 256 | tabnew |
| 257 | tabnew |
| 258 | tabnew |
| 259 | tabnext 3 |
| 260 | mksession! Xtest_mks.out |
| 261 | tabnew |
| 262 | tabnew |
| 263 | tabnext 2 |
| 264 | source Xtest_mks.out |
| 265 | call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs') |
| 266 | call assert_equal(3, tabpagenr(), 'session restore should restore the active tab') |
| 267 | call delete('Xtest_mks.out') |
| 268 | endfunc |
| 269 | |
Bram Moolenaar | d39e275 | 2019-01-26 20:07:38 +0100 | [diff] [blame] | 270 | func Test_mksession_buffer_count() |
| 271 | set hidden |
| 272 | |
| 273 | " Edit exactly three files in the current session. |
| 274 | %bwipe! |
| 275 | e Xfoo | tabe Xbar | tabe Xbaz |
| 276 | tabdo write |
| 277 | mksession! Xtest_mks.out |
| 278 | |
| 279 | " Verify that loading the session does not create additional buffers. |
| 280 | %bwipe! |
| 281 | source Xtest_mks.out |
| 282 | call assert_equal(3, len(getbufinfo())) |
| 283 | |
| 284 | " Clean up. |
| 285 | call delete('Xfoo') |
| 286 | call delete('Xbar') |
| 287 | call delete('Xbaz') |
| 288 | call delete('Xtest_mks.out') |
| 289 | %bwipe! |
| 290 | set hidden& |
| 291 | endfunc |
| 292 | |
Bram Moolenaar | e3c74d2 | 2019-01-12 16:29:30 +0100 | [diff] [blame] | 293 | if has('extra_search') |
| 294 | |
| 295 | func Test_mksession_hlsearch() |
| 296 | set hlsearch |
| 297 | mksession! Xtest_mks.out |
| 298 | nohlsearch |
| 299 | source Xtest_mks.out |
| 300 | call assert_equal(1, v:hlsearch, 'session should restore search highlighting state') |
| 301 | nohlsearch |
| 302 | mksession! Xtest_mks.out |
| 303 | source Xtest_mks.out |
| 304 | call assert_equal(0, v:hlsearch, 'session should restore search highlighting state') |
| 305 | call delete('Xtest_mks.out') |
| 306 | endfunc |
| 307 | |
| 308 | endif |
| 309 | |
| 310 | |
Bram Moolenaar | 26d4b89 | 2018-07-04 22:26:28 +0200 | [diff] [blame] | 311 | func Test_mksession_blank_windows() |
| 312 | split |
| 313 | split |
| 314 | split |
| 315 | 3 wincmd w |
| 316 | mksession! Xtest_mks.out |
| 317 | split |
| 318 | split |
| 319 | 2 wincmd w |
| 320 | source Xtest_mks.out |
| 321 | call assert_equal(4, winnr('$'), 'session restore should restore number of windows') |
| 322 | call assert_equal(3, winnr(), 'session restore should restore the active window') |
| 323 | call delete('Xtest_mks.out') |
| 324 | endfunc |
| 325 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 326 | if has('terminal') |
| 327 | |
| 328 | func Test_mksession_terminal_shell() |
| 329 | terminal |
| 330 | mksession! Xtest_mks.out |
| 331 | let lines = readfile('Xtest_mks.out') |
| 332 | let term_cmd = '' |
| 333 | for line in lines |
| 334 | if line =~ '^terminal' |
| 335 | let term_cmd = line |
| 336 | elseif line =~ 'badd.*' . &shell |
| 337 | call assert_report('unexpected shell line: ' . line) |
| 338 | endif |
| 339 | endfor |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 340 | call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 341 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 342 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 343 | call delete('Xtest_mks.out') |
| 344 | endfunc |
| 345 | |
| 346 | func Test_mksession_terminal_no_restore_cmdarg() |
| 347 | terminal ++norestore |
| 348 | mksession! Xtest_mks.out |
| 349 | let lines = readfile('Xtest_mks.out') |
| 350 | let term_cmd = '' |
| 351 | for line in lines |
| 352 | if line =~ '^terminal' |
| 353 | call assert_report('session must not restore teminal') |
| 354 | endif |
| 355 | endfor |
| 356 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 357 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 358 | call delete('Xtest_mks.out') |
| 359 | endfunc |
| 360 | |
| 361 | func Test_mksession_terminal_no_restore_funcarg() |
| 362 | call term_start(&shell, {'norestore': 1}) |
| 363 | mksession! Xtest_mks.out |
| 364 | let lines = readfile('Xtest_mks.out') |
| 365 | let term_cmd = '' |
| 366 | for line in lines |
| 367 | if line =~ '^terminal' |
| 368 | call assert_report('session must not restore teminal') |
| 369 | endif |
| 370 | endfor |
| 371 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 372 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 373 | call delete('Xtest_mks.out') |
| 374 | endfunc |
| 375 | |
| 376 | func Test_mksession_terminal_no_restore_func() |
| 377 | terminal |
| 378 | call term_setrestore(bufnr('%'), 'NONE') |
| 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_ssop() |
| 393 | terminal |
| 394 | set sessionoptions-=terminal |
| 395 | mksession! Xtest_mks.out |
| 396 | let lines = readfile('Xtest_mks.out') |
| 397 | let term_cmd = '' |
| 398 | for line in lines |
| 399 | if line =~ '^terminal' |
| 400 | call assert_report('session must not restore teminal') |
| 401 | endif |
| 402 | endfor |
| 403 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 404 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 405 | call delete('Xtest_mks.out') |
| 406 | set sessionoptions& |
| 407 | endfunc |
| 408 | |
| 409 | func Test_mksession_terminal_restore_other() |
| 410 | terminal |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 411 | eval bufnr('%')->term_setrestore('other') |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 412 | mksession! Xtest_mks.out |
| 413 | let lines = readfile('Xtest_mks.out') |
| 414 | let term_cmd = '' |
| 415 | for line in lines |
| 416 | if line =~ '^terminal' |
| 417 | let term_cmd = line |
| 418 | endif |
| 419 | endfor |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 420 | call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 421 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 422 | call StopShellInTerminal(bufnr('%')) |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame] | 423 | call delete('Xtest_mks.out') |
| 424 | endfunc |
| 425 | |
| 426 | endif " has('terminal') |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 427 | |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 428 | " Test :mkview with a file argument. |
| 429 | func Test_mkview_file() |
| 430 | " Create a view with line number and a fold. |
| 431 | help :mkview |
| 432 | set number |
Bram Moolenaar | 2bf4fe0 | 2018-08-30 14:04:25 +0200 | [diff] [blame] | 433 | norm! V}zf0 |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 434 | let pos = getpos('.') |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 435 | let linefoldclosed1 = foldclosed('.') |
| 436 | mkview! Xview |
| 437 | set nonumber |
| 438 | norm! zrj |
| 439 | " We can close the help window, as mkview with a file name should |
| 440 | " generate a command to edit the file. |
| 441 | helpclose |
| 442 | |
| 443 | source Xview |
| 444 | call assert_equal(1, &number) |
| 445 | call assert_match('\*:mkview\*$', getline('.')) |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 446 | call assert_equal(pos, getpos('.')) |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 447 | call assert_equal(linefoldclosed1, foldclosed('.')) |
| 448 | |
| 449 | " Creating a view again with the same file name should fail (file |
| 450 | " already exists). But with a !, the previous view should be |
| 451 | " overwritten without error. |
| 452 | help :loadview |
| 453 | call assert_fails('mkview Xview', 'E189:') |
| 454 | call assert_match('\*:loadview\*$', getline('.')) |
| 455 | mkview! Xview |
| 456 | call assert_match('\*:loadview\*$', getline('.')) |
| 457 | |
| 458 | call delete('Xview') |
| 459 | bwipe |
| 460 | endfunc |
| 461 | |
| 462 | " Test :mkview and :loadview with a custom 'viewdir'. |
| 463 | func Test_mkview_loadview_with_viewdir() |
| 464 | set viewdir=Xviewdir |
| 465 | |
| 466 | help :mkview |
| 467 | set number |
| 468 | norm! V}zf |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 469 | let pos = getpos('.') |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 470 | let linefoldclosed1 = foldclosed('.') |
| 471 | mkview 1 |
| 472 | set nonumber |
| 473 | norm! zrj |
| 474 | |
| 475 | loadview 1 |
| 476 | |
| 477 | " The directory Xviewdir/ should have been created and the view |
| 478 | " should be stored in that directory. |
| 479 | call assert_equal('Xviewdir/' . |
| 480 | \ substitute( |
| 481 | \ substitute( |
| 482 | \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', |
| 483 | \ glob('Xviewdir/*')) |
| 484 | call assert_equal(1, &number) |
| 485 | call assert_match('\*:mkview\*$', getline('.')) |
Bram Moolenaar | dd5d18e | 2018-08-30 14:16:06 +0200 | [diff] [blame] | 486 | call assert_equal(pos, getpos('.')) |
Bram Moolenaar | 627cb6a | 2018-08-28 22:19:31 +0200 | [diff] [blame] | 487 | call assert_equal(linefoldclosed1, foldclosed('.')) |
| 488 | |
| 489 | call delete('Xviewdir', 'rf') |
| 490 | set viewdir& |
| 491 | helpclose |
| 492 | endfunc |
| 493 | |
| 494 | func Test_mkview_no_file_name() |
| 495 | new |
| 496 | " :mkview or :mkview {nr} should fail in a unnamed buffer. |
| 497 | call assert_fails('mkview', 'E32:') |
| 498 | call assert_fails('mkview 1', 'E32:') |
| 499 | |
| 500 | " :mkview {file} should succeed in a unnamed buffer. |
| 501 | mkview Xview |
| 502 | help |
| 503 | source Xview |
| 504 | call assert_equal('', bufname('%')) |
| 505 | |
| 506 | call delete('Xview') |
| 507 | %bwipe |
| 508 | endfunc |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 509 | |
Bram Moolenaar | 555de4e | 2019-01-21 23:03:49 +0100 | [diff] [blame] | 510 | " A clean session (one empty buffer, one window, and one tab) should not |
| 511 | " set any error messages when sourced because no commands should fail. |
| 512 | func Test_mksession_no_errmsg() |
| 513 | let v:errmsg = '' |
| 514 | %bwipe! |
| 515 | mksession! Xtest_mks.out |
| 516 | source Xtest_mks.out |
| 517 | call assert_equal('', v:errmsg) |
| 518 | call delete('Xtest_mks.out') |
| 519 | endfunc |
| 520 | |
Bram Moolenaar | ad36a35 | 2019-01-24 13:34:42 +0100 | [diff] [blame] | 521 | func Test_mksession_quote_in_filename() |
Bram Moolenaar | 9e79ccb | 2019-01-24 15:57:30 +0100 | [diff] [blame] | 522 | if !has('unix') |
| 523 | " only Unix can handle this weird filename |
| 524 | return |
| 525 | endif |
Bram Moolenaar | ad36a35 | 2019-01-24 13:34:42 +0100 | [diff] [blame] | 526 | let v:errmsg = '' |
| 527 | %bwipe! |
| 528 | split another |
| 529 | split x'y\"z |
| 530 | mksession! Xtest_mks_quoted.out |
| 531 | %bwipe! |
| 532 | source Xtest_mks_quoted.out |
| 533 | call assert_true(bufexists("x'y\"z")) |
| 534 | |
| 535 | %bwipe! |
| 536 | call delete('Xtest_mks_quoted.out') |
| 537 | endfunc |
| 538 | |
Bram Moolenaar | 66f0e6c | 2019-09-28 19:08:45 +0200 | [diff] [blame^] | 539 | " Test for storing global variables in a session file |
| 540 | func Test_mksession_globals() |
| 541 | set sessionoptions+=globals |
| 542 | |
| 543 | " create different global variables |
| 544 | let g:Global_string = "Sun is shining" |
| 545 | let g:Global_count = 100 |
| 546 | let g:Global_pi = 3.14 |
| 547 | |
| 548 | mksession! Xtest_mks.out |
| 549 | |
| 550 | unlet g:Global_string |
| 551 | unlet g:Global_count |
| 552 | unlet g:Global_pi |
| 553 | |
| 554 | source Xtest_mks.out |
| 555 | call assert_equal("Sun is shining", g:Global_string) |
| 556 | call assert_equal(100, g:Global_count) |
| 557 | call assert_equal(3.14, g:Global_pi) |
| 558 | |
| 559 | unlet g:Global_string |
| 560 | unlet g:Global_count |
| 561 | unlet g:Global_pi |
| 562 | call delete('Xtest_mks.out') |
| 563 | set sessionoptions& |
| 564 | endfunc |
| 565 | |
| 566 | " Test for changing backslash to forward slash in filenames |
| 567 | func Test_mksession_slash() |
| 568 | enew |
| 569 | %bwipe! |
| 570 | e a\\b\\c |
| 571 | mksession! Xtest_mks1.out |
| 572 | set sessionoptions+=slash |
| 573 | mksession! Xtest_mks2.out |
| 574 | |
| 575 | %bwipe! |
| 576 | source Xtest_mks1.out |
| 577 | call assert_equal('a\b\c', bufname('')) |
| 578 | %bwipe! |
| 579 | source Xtest_mks2.out |
| 580 | call assert_equal('a/b/c', bufname('')) |
| 581 | |
| 582 | %bwipe! |
| 583 | call delete('Xtest_mks1.out') |
| 584 | call delete('Xtest_mks2.out') |
| 585 | set sessionoptions& |
| 586 | endfunc |
| 587 | |
| 588 | " Test for storing global and local argument list in a session file |
| 589 | func Test_mkseesion_arglocal() |
| 590 | enew | only |
| 591 | n a b c |
| 592 | new |
| 593 | arglocal |
| 594 | mksession! Xtest_mks.out |
| 595 | |
| 596 | %bwipe! |
| 597 | %argdelete |
| 598 | argglobal |
| 599 | source Xtest_mks.out |
| 600 | call assert_equal(2, winnr('$')) |
| 601 | call assert_equal(2, arglistid(1)) |
| 602 | call assert_equal(0, arglistid(2)) |
| 603 | |
| 604 | %bwipe! |
| 605 | %argdelete |
| 606 | argglobal |
| 607 | call delete('Xtest_mks.out') |
| 608 | endfunc |
| 609 | |
| 610 | " Test for changing directory to the session file directory |
| 611 | func Test_mksession_sesdir() |
| 612 | call mkdir('Xproj') |
| 613 | mksession! Xproj/Xtest_mks1.out |
| 614 | set sessionoptions-=curdir |
| 615 | set sessionoptions+=sesdir |
| 616 | mksession! Xproj/Xtest_mks2.out |
| 617 | |
| 618 | source Xproj/Xtest_mks1.out |
| 619 | call assert_equal('testdir', fnamemodify(getcwd(), ':t')) |
| 620 | source Xproj/Xtest_mks2.out |
| 621 | call assert_equal('Xproj', fnamemodify(getcwd(), ':t')) |
| 622 | cd .. |
| 623 | |
| 624 | set sessionoptions& |
| 625 | call delete('Xproj', 'rf') |
| 626 | endfunc |
| 627 | |
| 628 | " Test for storing the 'lines' and 'columns' settings |
| 629 | func Test_mksession_resize() |
| 630 | mksession! Xtest_mks1.out |
| 631 | set sessionoptions+=resize |
| 632 | mksession! Xtest_mks2.out |
| 633 | |
| 634 | let lines = readfile('Xtest_mks1.out') |
| 635 | let found_resize = v:false |
| 636 | for line in lines |
| 637 | if line =~ '^set lines=' |
| 638 | let found_resize = v:true |
| 639 | endif |
| 640 | endfor |
| 641 | call assert_equal(v:false, found_resize) |
| 642 | let lines = readfile('Xtest_mks2.out') |
| 643 | let found_resize = v:false |
| 644 | for line in lines |
| 645 | if line =~ '^set lines=' |
| 646 | let found_resize = v:true |
| 647 | endif |
| 648 | endfor |
| 649 | call assert_equal(v:true, found_resize) |
| 650 | |
| 651 | call delete('Xtest_mks1.out') |
| 652 | call delete('Xtest_mks2.out') |
| 653 | set sessionoptions& |
| 654 | endfunc |
| 655 | |
Bram Moolenaar | 8750026 | 2019-08-01 23:05:49 +0200 | [diff] [blame] | 656 | func s:ClearMappings() |
| 657 | mapclear |
| 658 | omapclear |
| 659 | mapclear! |
| 660 | lmapclear |
| 661 | tmapclear |
| 662 | endfunc |
| 663 | |
| 664 | func Test_mkvimrc() |
| 665 | let entries = [ |
| 666 | \ ['', 'nothing', '<Nop>'], |
| 667 | \ ['n', 'normal', 'NORMAL'], |
| 668 | \ ['v', 'visual', 'VISUAL'], |
| 669 | \ ['s', 'select', 'SELECT'], |
| 670 | \ ['x', 'visualonly', 'VISUALONLY'], |
| 671 | \ ['o', 'operator', 'OPERATOR'], |
| 672 | \ ['i', 'insert', 'INSERT'], |
| 673 | \ ['l', 'lang', 'LANG'], |
| 674 | \ ['c', 'command', 'COMMAND'], |
| 675 | \ ['t', 'terminal', 'TERMINAL'], |
| 676 | \ ] |
| 677 | for entry in entries |
| 678 | exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2] |
| 679 | endfor |
| 680 | |
| 681 | mkvimrc Xtestvimrc |
| 682 | |
| 683 | call s:ClearMappings() |
| 684 | for entry in entries |
| 685 | call assert_equal('', maparg(entry[1], entry[0])) |
| 686 | endfor |
| 687 | |
| 688 | source Xtestvimrc |
| 689 | |
| 690 | for entry in entries |
| 691 | call assert_equal(entry[2], maparg(entry[1], entry[0])) |
| 692 | endfor |
| 693 | |
| 694 | call s:ClearMappings() |
| 695 | call delete('Xtestvimrc') |
| 696 | endfunc |
| 697 | |
Bram Moolenaar | 555de4e | 2019-01-21 23:03:49 +0100 | [diff] [blame] | 698 | |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 699 | " vim: shiftwidth=2 sts=2 expandtab |