Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 1 | " Tests for various Visual mode. |
Bram Moolenaar | 019b9c6 | 2016-03-05 17:26:00 +0100 | [diff] [blame] | 2 | if !has('visual') |
| 3 | finish |
| 4 | endif |
| 5 | |
Bram Moolenaar | c3c766e | 2017-03-08 22:55:19 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | 019b9c6 | 2016-03-05 17:26:00 +0100 | [diff] [blame] | 7 | func Test_block_shift_multibyte() |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 8 | " Uses double-wide character. |
| 9 | if !has('multi_byte') |
| 10 | return |
| 11 | endif |
Bram Moolenaar | 019b9c6 | 2016-03-05 17:26:00 +0100 | [diff] [blame] | 12 | split |
| 13 | call setline(1, ['xヹxxx', 'ヹxxx']) |
| 14 | exe "normal 1G0l\<C-V>jl>" |
| 15 | call assert_equal('x ヹxxx', getline(1)) |
| 16 | call assert_equal(' ヹxxx', getline(2)) |
| 17 | q! |
| 18 | endfunc |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 19 | |
Bram Moolenaar | bae5a17 | 2017-08-06 15:42:06 +0200 | [diff] [blame] | 20 | func Test_block_shift_overflow() |
| 21 | " This used to cause a multiplication overflow followed by a crash. |
| 22 | new |
| 23 | normal ii |
| 24 | exe "normal \<C-V>876543210>" |
| 25 | q! |
| 26 | endfunc |
| 27 | |
Bram Moolenaar | f8eb9c5 | 2017-01-02 17:31:24 +0100 | [diff] [blame] | 28 | func Test_dotregister_paste() |
| 29 | new |
| 30 | exe "norm! ihello world\<esc>" |
| 31 | norm! 0ve".p |
| 32 | call assert_equal('hello world world', getline(1)) |
| 33 | q! |
| 34 | endfunc |
Bram Moolenaar | 23fa81d | 2017-02-01 21:50:21 +0100 | [diff] [blame] | 35 | |
| 36 | func Test_Visual_ctrl_o() |
| 37 | new |
| 38 | call setline(1, ['one', 'two', 'three']) |
| 39 | call cursor(1,2) |
| 40 | set noshowmode |
| 41 | set tw=0 |
| 42 | call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx') |
| 43 | call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3)) |
| 44 | call assert_equal(88, &tw) |
| 45 | set tw& |
| 46 | bw! |
| 47 | endfu |
Bram Moolenaar | 84b2a38 | 2017-02-17 11:40:00 +0100 | [diff] [blame] | 48 | |
| 49 | func Test_Visual_vapo() |
| 50 | new |
| 51 | normal oxx |
| 52 | normal vapo |
| 53 | bwipe! |
| 54 | endfunc |
Bram Moolenaar | 46522af | 2017-02-18 23:12:01 +0100 | [diff] [blame] | 55 | |
| 56 | func Test_Visual_inner_quote() |
| 57 | new |
| 58 | normal oxX |
| 59 | normal vki' |
| 60 | bwipe! |
| 61 | endfunc |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 62 | |
| 63 | " Test for Visual mode not being reset causing E315 error. |
| 64 | func TriggerTheProblem() |
| 65 | " At this point there is no visual selection because :call reset it. |
| 66 | " Let's restore the selection: |
| 67 | normal gv |
| 68 | '<,'>del _ |
| 69 | try |
| 70 | exe "normal \<Esc>" |
| 71 | catch /^Vim\%((\a\+)\)\=:E315/ |
| 72 | echom 'Snap! E315 error!' |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 73 | let g:msg = 'Snap! E315 error!' |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 74 | endtry |
| 75 | endfunc |
| 76 | |
| 77 | func Test_visual_mode_reset() |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 78 | enew |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 79 | let g:msg = "Everything's fine." |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 80 | enew |
| 81 | setl buftype=nofile |
| 82 | call append(line('$'), 'Delete this line.') |
| 83 | |
| 84 | " NOTE: this has to be done by a call to a function because executing :del |
| 85 | " the ex-way will require the colon operator which resets the visual mode |
| 86 | " thus preventing the problem: |
| 87 | exe "normal! GV:call TriggerTheProblem()\<CR>" |
| 88 | call assert_equal("Everything's fine.", g:msg) |
| 89 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 90 | endfunc |
Bram Moolenaar | 67418d9 | 2017-10-15 22:07:39 +0200 | [diff] [blame] | 91 | |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 92 | " Test for visual block shift and tab characters. |
| 93 | func Test_block_shift_tab() |
| 94 | enew! |
| 95 | call append(0, repeat(['one two three'], 5)) |
| 96 | call cursor(1,1) |
| 97 | exe "normal i\<C-G>u" |
| 98 | exe "normal fe\<C-V>4jR\<Esc>ugvr1" |
| 99 | call assert_equal('on1 two three', getline(1)) |
| 100 | call assert_equal('on1 two three', getline(2)) |
| 101 | call assert_equal('on1 two three', getline(5)) |
| 102 | |
| 103 | enew! |
| 104 | call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5)) |
| 105 | call cursor(1,1) |
| 106 | exe "normal \<C-V>4jI \<Esc>j<<11|D" |
| 107 | exe "normal j7|a\<Tab>\<Tab>" |
| 108 | exe "normal j7|a\<Tab>\<Tab> " |
| 109 | exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<" |
| 110 | call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) |
| 111 | call assert_equal('abcdefghij', getline(2)) |
| 112 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) |
| 113 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(4)) |
| 114 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) |
| 115 | |
| 116 | %s/\s\+//g |
| 117 | call cursor(1,1) |
| 118 | exe "normal \<C-V>4jI \<Esc>j<<" |
| 119 | exe "normal j7|a\<Tab>\<Tab>" |
| 120 | exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>" |
| 121 | exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<" |
| 122 | call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) |
| 123 | call assert_equal('abcdefghij', getline(2)) |
| 124 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) |
| 125 | call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4)) |
| 126 | call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) |
| 127 | |
| 128 | enew! |
| 129 | endfunc |
| 130 | |
| 131 | " Tests Blockwise Visual when there are TABs before the text. |
| 132 | func Test_blockwise_visual() |
| 133 | enew! |
| 134 | call append(0, ['123456', |
| 135 | \ '234567', |
| 136 | \ '345678', |
| 137 | \ '', |
| 138 | \ 'test text test tex start here', |
| 139 | \ "\t\tsome text", |
| 140 | \ "\t\ttest text", |
| 141 | \ 'test text']) |
| 142 | call cursor(1,1) |
| 143 | exe "normal /start here$\<CR>" |
| 144 | exe 'normal "by$' . "\<C-V>jjlld" |
| 145 | exe "normal /456$\<CR>" |
| 146 | exe "normal \<C-V>jj" . '"bP' |
| 147 | call assert_equal(['123start here56', |
| 148 | \ '234start here67', |
| 149 | \ '345start here78', |
| 150 | \ '', |
| 151 | \ 'test text test tex rt here', |
| 152 | \ "\t\tsomext", |
| 153 | \ "\t\ttesext"], getline(1, 7)) |
| 154 | |
| 155 | enew! |
| 156 | endfunc |
| 157 | |
| 158 | " Test Virtual replace mode. |
| 159 | func Test_virtual_replace() |
Bram Moolenaar | e780848 | 2018-03-06 13:17:23 +0100 | [diff] [blame] | 160 | let save_t_kD = &t_kD |
| 161 | let save_t_kb = &t_kb |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 162 | exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" |
| 163 | enew! |
| 164 | exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" |
| 165 | call cursor(1,1) |
| 166 | set ai bs=2 |
| 167 | exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" |
| 168 | call assert_equal([' 1', |
| 169 | \ ' A', |
| 170 | \ ' BCDEFGHIJ', |
| 171 | \ ' KL', |
| 172 | \ ' MNO', |
| 173 | \ ' PQR', |
| 174 | \ ], getline(1, 6)) |
| 175 | normal G |
| 176 | mark a |
| 177 | exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" |
| 178 | exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29) |
| 179 | call assert_equal([' 1', |
| 180 | \ 'abcdefghi', |
| 181 | \ 'jk lmn', |
| 182 | \ ' opq rst', |
| 183 | \ 'uvwxyz'], getline(7, 11)) |
| 184 | normal G |
| 185 | exe "normal iab\tcdefghi\tjkl" |
| 186 | exe "normal 0gRAB......CDEFGHI.J\<Esc>o" |
| 187 | exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" |
| 188 | call assert_equal(['AB......CDEFGHI.Jkl', |
| 189 | \ 'AB IJKLMNO QRst'], getline(12, 13)) |
| 190 | enew! |
Bram Moolenaar | e780848 | 2018-03-06 13:17:23 +0100 | [diff] [blame] | 191 | set noai bs&vim |
| 192 | let &t_kD = save_t_kD |
| 193 | let &t_kb = save_t_kb |
Bram Moolenaar | 63e82db | 2018-03-06 12:10:48 +0100 | [diff] [blame] | 194 | endfunc |
| 195 | |
| 196 | " Test Virtual replace mode. |
| 197 | func Test_virtual_replace2() |
| 198 | enew! |
| 199 | set bs=2 |
| 200 | exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" |
| 201 | call cursor(1,1) |
| 202 | " Test 1: Test that del deletes the newline |
| 203 | exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" |
| 204 | call assert_equal(['0 1', |
| 205 | \ 'A', |
| 206 | \ 'BCDEFGHIJ', |
| 207 | \ ' KL', |
| 208 | \ 'MNO', |
| 209 | \ 'PQR', |
| 210 | \ ], getline(1, 6)) |
| 211 | " Test 2: |
| 212 | " a newline is not deleted, if no newline has been added in virtual replace mode |
| 213 | %d_ |
| 214 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 215 | call cursor(2,1) |
| 216 | exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" |
| 217 | call assert_equal(['abcd', |
| 218 | \ '123h', |
| 219 | \ 'ijkl'], getline(1, '$')) |
| 220 | " Test 3: |
| 221 | " a newline is deleted, if a newline has been inserted before in virtual replace mode |
| 222 | %d_ |
| 223 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 224 | call cursor(2,1) |
| 225 | exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" |
| 226 | call assert_equal(['abcd', |
| 227 | \ '1234', |
| 228 | \ 'ijkl'], getline(1, '$')) |
| 229 | " Test 4: |
| 230 | " delete add a newline, delete it, add it again and check undo |
| 231 | %d_ |
| 232 | call setline(1, ['abcd', 'efgh', 'ijkl']) |
| 233 | call cursor(2,1) |
| 234 | " break undo sequence explicitly |
| 235 | let &ul = &ul |
| 236 | exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" |
| 237 | let &ul = &ul |
| 238 | call assert_equal(['abcd', |
| 239 | \ '123456', |
| 240 | \ ''], getline(1, '$')) |
| 241 | norm! u |
| 242 | call assert_equal(['abcd', |
| 243 | \ 'efgh', |
| 244 | \ 'ijkl'], getline(1, '$')) |
| 245 | " clean up |
| 246 | %d_ |
| 247 | set bs&vim |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 248 | endfunc |