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