blob: 0e6231fd6da55a4174c92b1b0f5f9d08031c1ec7 [file] [log] [blame]
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +01001" Tests for various Visual mode.
Bram Moolenaar019b9c62016-03-05 17:26:00 +01002if !has('visual')
3 finish
4endif
5
Bram Moolenaarc3c766e2017-03-08 22:55:19 +01006
Bram Moolenaar019b9c62016-03-05 17:26:00 +01007func Test_block_shift_multibyte()
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +01008 " Uses double-wide character.
9 if !has('multi_byte')
10 return
11 endif
Bram Moolenaar019b9c62016-03-05 17:26:00 +010012 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!
18endfunc
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +010019
Bram Moolenaarbae5a172017-08-06 15:42:06 +020020func 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!
26endfunc
27
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +010028func 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!
34endfunc
Bram Moolenaar23fa81d2017-02-01 21:50:21 +010035
36func 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!
47endfu
Bram Moolenaar84b2a382017-02-17 11:40:00 +010048
49func Test_Visual_vapo()
50 new
51 normal oxx
52 normal vapo
53 bwipe!
54endfunc
Bram Moolenaar46522af2017-02-18 23:12:01 +010055
56func Test_Visual_inner_quote()
57 new
58 normal oxX
59 normal vki'
60 bwipe!
61endfunc
Bram Moolenaar75373f32017-08-07 22:02:30 +020062
63" Test for Visual mode not being reset causing E315 error.
64func 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!'
73 let g:msg='Snap! E315 error!'
74 endtry
75endfunc
76
77func Test_visual_mode_reset()
Bram Moolenaar75373f32017-08-07 22:02:30 +020078 enew
79 let g:msg="Everything's fine."
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 Moolenaar75373f32017-08-07 22:02:30 +020090endfunc
Bram Moolenaar67418d92017-10-15 22:07:39 +020091