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