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 | |
| 6 | if !has('multi_byte') || !has('mksession') |
| 7 | finish |
| 8 | endif |
| 9 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame^] | 10 | source shared.vim |
| 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', |
| 25 | \ 'Aäöü three mulTibyte characters' |
| 26 | \ ]) |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 27 | let tmpfile = 'Xtemp' |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 28 | 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 Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 68 | mksession! Xtest_mks.out |
| 69 | 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] | 70 | 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 Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 101 | call delete('Xtest_mks.out') |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 102 | call delete(tmpfile) |
| 103 | let &wrap = wrap_save |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame^] | 104 | set sessionoptions& |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 105 | endfunc |
| 106 | |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 107 | func Test_mksession_winheight() |
| 108 | new |
| 109 | set winheight=10 winminheight=2 |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 110 | mksession! Xtest_mks.out |
| 111 | source Xtest_mks.out |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 112 | |
Bram Moolenaar | c9b56b2 | 2017-01-29 14:14:09 +0100 | [diff] [blame] | 113 | call delete('Xtest_mks.out') |
Bram Moolenaar | 36ae89c | 2017-01-28 17:11:14 +0100 | [diff] [blame] | 114 | endfunc |
| 115 | |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 116 | func 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 * |
| 125 | endfunc |
| 126 | |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 127 | func 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 Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 153 | call delete('Xtest_mks.out') |
| 154 | endfunc |
| 155 | |
Bram Moolenaar | 4d8bac8 | 2018-03-09 21:33:34 +0100 | [diff] [blame^] | 156 | if has('terminal') |
| 157 | |
| 158 | func 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') |
| 174 | endfunc |
| 175 | |
| 176 | func 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') |
| 189 | endfunc |
| 190 | |
| 191 | func 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') |
| 204 | endfunc |
| 205 | |
| 206 | func 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') |
| 220 | endfunc |
| 221 | |
| 222 | func 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& |
| 237 | endfunc |
| 238 | |
| 239 | func 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') |
| 254 | endfunc |
| 255 | |
| 256 | endif " has('terminal') |
Bram Moolenaar | 4bebc9a | 2017-08-30 21:07:38 +0200 | [diff] [blame] | 257 | |
Bram Moolenaar | 79da563 | 2017-02-01 22:52:44 +0100 | [diff] [blame] | 258 | |
Bram Moolenaar | eca626f | 2016-12-01 18:47:38 +0100 | [diff] [blame] | 259 | " vim: shiftwidth=2 sts=2 expandtab |