Bram Moolenaar | f52f9ea | 2018-06-27 20:49:44 +0200 | [diff] [blame^] | 1 | " Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc. |
Bram Moolenaar | c812996 | 2017-01-22 20:04:51 +0100 | [diff] [blame] | 2 | |
| 3 | func Test_put_block() |
| 4 | if !has('multi_byte') |
| 5 | return |
| 6 | endif |
| 7 | new |
| 8 | call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x') |
| 9 | call feedkeys("\<C-V>y", 'x') |
| 10 | call feedkeys("gg0p", 'x') |
| 11 | call assert_equal("\u2500x", getline(1)) |
| 12 | bwipe! |
| 13 | endfunc |
Bram Moolenaar | 9957a10 | 2017-01-23 21:53:53 +0100 | [diff] [blame] | 14 | |
| 15 | func Test_put_char_block() |
| 16 | new |
| 17 | call setline(1, ['Line 1', 'Line 2']) |
| 18 | f Xfile_put |
| 19 | " visually select both lines and put the cursor at the top of the visual |
| 20 | " selection and then put the buffer name over it |
| 21 | exe "norm! G0\<c-v>ke\"%p" |
| 22 | call assert_equal(['Xfile_put 1', 'Xfile_put 2'], getline(1,2)) |
| 23 | bw! |
| 24 | endfunc |
Bram Moolenaar | 941c12d | 2017-01-24 19:55:43 +0100 | [diff] [blame] | 25 | |
| 26 | func Test_put_char_block2() |
| 27 | new |
| 28 | let a = [ getreg('a'), getregtype('a') ] |
| 29 | call setreg('a', ' one ', 'v') |
| 30 | call setline(1, ['Line 1', '', 'Line 3', '']) |
| 31 | " visually select the first 3 lines and put register a over it |
| 32 | exe "norm! ggl\<c-v>2j2l\"ap" |
| 33 | call assert_equal(['L one 1', '', 'L one 3', ''], getline(1,4)) |
| 34 | " clean up |
| 35 | bw! |
| 36 | call setreg('a', a[0], a[1]) |
| 37 | endfunc |
Bram Moolenaar | 18d90b9 | 2017-06-27 15:39:14 +0200 | [diff] [blame] | 38 | |
| 39 | func Test_put_lines() |
| 40 | new |
| 41 | let a = [ getreg('a'), getregtype('a') ] |
| 42 | call setline(1, ['Line 1', 'Line2', 'Line 3', '']) |
| 43 | exe 'norm! gg"add"AddG""p' |
| 44 | call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$')) |
| 45 | " clean up |
| 46 | bw! |
| 47 | call setreg('a', a[0], a[1]) |
| 48 | endfunc |
Bram Moolenaar | 833093b | 2018-05-23 21:53:52 +0200 | [diff] [blame] | 49 | |
| 50 | func Test_put_expr() |
| 51 | new |
| 52 | call setline(1, repeat(['A'], 6)) |
| 53 | exec "1norm! \"=line('.')\<cr>p" |
| 54 | norm! j0. |
| 55 | norm! j0. |
| 56 | exec "4norm! \"=\<cr>P" |
| 57 | norm! j0. |
| 58 | norm! j0. |
| 59 | call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$')) |
| 60 | bw! |
| 61 | endfunc |
Bram Moolenaar | f52f9ea | 2018-06-27 20:49:44 +0200 | [diff] [blame^] | 62 | |
| 63 | func Test_put_fails_when_nomodifiable() |
| 64 | new |
| 65 | set nomodifiable |
| 66 | |
| 67 | normal! yy |
| 68 | call assert_fails(':put', 'E21') |
| 69 | call assert_fails(':put!', 'E21') |
| 70 | call assert_fails(':normal! p', 'E21') |
| 71 | call assert_fails(':normal! gp', 'E21') |
| 72 | call assert_fails(':normal! P', 'E21') |
| 73 | call assert_fails(':normal! gP', 'E21') |
| 74 | |
| 75 | if has('mouse') |
| 76 | set mouse=n |
| 77 | call assert_fails('execute "normal! \<MiddleMouse>"', 'E21') |
| 78 | set mouse& |
| 79 | endif |
| 80 | |
| 81 | bwipeout! |
| 82 | endfunc |
| 83 | |
| 84 | " A bug was discovered where the Normal mode put commands (e.g., "p") would |
| 85 | " output duplicate error messages when invoked in a non-modifiable buffer. |
| 86 | func Test_put_p_errmsg_nodup() |
| 87 | new |
| 88 | set nomodifiable |
| 89 | |
| 90 | normal! yy |
| 91 | |
| 92 | func Capture_p_error() |
| 93 | redir => s:p_err |
| 94 | normal! p |
| 95 | redir END |
| 96 | endfunc |
| 97 | |
| 98 | silent! call Capture_p_error() |
| 99 | |
| 100 | " Error message output within a function should be three lines (the function |
| 101 | " name, the line number, and the error message). |
| 102 | call assert_equal(3, count(s:p_err, "\n")) |
| 103 | |
| 104 | delfunction Capture_p_error |
| 105 | bwipeout! |
| 106 | endfunc |