" " Tests for register operations " " This test must be executed first to check for empty and unset registers. func Test_aaa_empty_reg_test() call assert_fails('normal @@', 'E748:') call assert_fails('normal @%', 'E354:') call assert_fails('normal @#', 'E354:') call assert_fails('normal @!', 'E354:') call assert_fails('normal @:', 'E30:') call assert_fails('normal @.', 'E29:') endfunc func Test_yank_shows_register() enew set report=0 call setline(1, ['foo', 'bar']) " Line-wise exe 'norm! yy' call assert_equal('1 line yanked', v:statusmsg) exe 'norm! "zyy' call assert_equal('1 line yanked into "z', v:statusmsg) exe 'norm! yj' call assert_equal('2 lines yanked', v:statusmsg) exe 'norm! "zyj' call assert_equal('2 lines yanked into "z', v:statusmsg) " Block-wise exe "norm! \y" call assert_equal('block of 1 line yanked', v:statusmsg) exe "norm! \\"zy" call assert_equal('block of 1 line yanked into "z', v:statusmsg) exe "norm! \jy" call assert_equal('block of 2 lines yanked', v:statusmsg) exe "norm! \j\"zy" call assert_equal('block of 2 lines yanked into "z', v:statusmsg) bwipe! endfunc func Test_display_registers() e file1 e file2 call setline(1, ['foo', 'bar']) /bar exe 'norm! y2l"axx' call feedkeys("i\=2*4\n\") call feedkeys(":ls\n", 'xt') let a = execute('display') let b = execute('registers') call assert_equal(a, b) call assert_match('^\n--- Registers ---\n' \ . '"" a\n' \ . '"0 ba\n' \ . '"1 b\n' \ . '"a b\n' \ . '.*' \ . '"- a\n' \ . '.*' \ . '": ls\n' \ . '"% file2\n' \ . '"# file1\n' \ . '"/ bar\n' \ . '"= 2\*4', a) let a = execute('registers a') call assert_match('^\n--- Registers ---\n' \ . '"a b', a) let a = execute('registers :') call assert_match('^\n--- Registers ---\n' \ . '": ls', a) bwipe! endfunc " Check that replaying a typed sequence does not use an Esc and following " characters as an escape sequence. func Test_recording_esc_sequence() new try let save_F2 = &t_F2 catch endtry let t_F2 = "\OQ" call feedkeys("qqiTest\", "xt") call feedkeys("OQuirk\q", "xt") call feedkeys("Go\@q", "xt") call assert_equal(['Quirk', 'Test', 'Quirk', 'Test'], getline(1, 4)) bwipe! if exists('save_F2') let &t_F2 = save_F2 endif endfunc " Test for executing the last used register (@) func Test_last_used_exec_reg() " Test for the @: command let a = '' call feedkeys(":let a ..= 'Vim'\", 'xt') normal @: call assert_equal('VimVim', a) " Test for the @= command let x = '' let a = ":let x ..= 'Vim'\" exe "normal @=a\" normal @@ call assert_equal('VimVim', x) " Test for the @. command let a = '' call feedkeys("i:let a ..= 'Edit'\", 'xt') normal @. normal @@ call assert_equal('EditEdit', a) enew! endfunc func Test_get_register() enew edit Xfile1 edit Xfile2 call assert_equal('Xfile2', getreg('%')) call assert_equal('Xfile1', getreg('#')) call feedkeys("iTwo\", 'xt') call assert_equal('Two', getreg('.')) call assert_equal('', getreg('_')) call assert_beeps('normal ":yy') call assert_beeps('normal "%yy') call assert_beeps('normal ".yy') call assert_equal('', getreg("\")) call assert_equal('', getreg("\")) call assert_equal('', getreg("\")) call assert_equal('', getregtype('!')) enew! endfunc func Test_set_register() call assert_fails("call setreg('#', 200)", 'E86:') edit Xfile_alt_1 let b1 = bufnr('') edit Xfile_alt_2 let b2 = bufnr('') edit Xfile_alt_3 let b3 = bufnr('') call setreg('#', 'alt_1') call assert_equal('Xfile_alt_1', getreg('#')) call setreg('#', b2) call assert_equal('Xfile_alt_2', getreg('#')) let ab = 'regwrite' call setreg('=', '') call setreg('=', 'a', 'a') call setreg('=', 'b', 'a') call assert_equal('regwrite', getreg('=')) enew! endfunc func Test_ve_blockpaste() new set ve=all 0put =['QWERTZ','ASDFGH'] call cursor(1,1) exe ":norm! \3ljdP" call assert_equal(1, col('.')) call assert_equal(getline(1, 2), ['QWERTZ', 'ASDFGH']) call cursor(1,1) exe ":norm! \3ljd" call cursor(1,1) norm! $3lP call assert_equal(5, col('.')) call assert_equal(getline(1, 2), ['TZ QWER', 'GH ASDF']) set ve&vim bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab