Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 1 | " Tests for mappings and abbreviations |
| 2 | |
| 3 | if !has('multi_byte') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | func Test_abbreviation() |
| 8 | " abbreviation with 0x80 should work |
| 9 | inoreab чкпр vim |
| 10 | call feedkeys("Goчкпр \<Esc>", "xt") |
| 11 | call assert_equal('vim ', getline('$')) |
| 12 | iunab чкпр |
| 13 | set nomodified |
| 14 | endfunc |
| 15 | |
| 16 | func Test_map_ctrl_c_insert() |
| 17 | " mapping of ctrl-c in Insert mode |
| 18 | set cpo-=< cpo-=k |
| 19 | inoremap <c-c> <ctrl-c> |
| 20 | cnoremap <c-c> dummy |
| 21 | cunmap <c-c> |
| 22 | call feedkeys("GoTEST2: CTRL-C |\<C-C>A|\<Esc>", "xt") |
| 23 | call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$')) |
| 24 | unmap! <c-c> |
| 25 | set nomodified |
| 26 | endfunc |
| 27 | |
| 28 | func Test_map_ctrl_c_visual() |
| 29 | " mapping of ctrl-c in Visual mode |
| 30 | vnoremap <c-c> :<C-u>$put ='vmap works' |
| 31 | call feedkeys("GV\<C-C>\<CR>", "xt") |
| 32 | call assert_equal('vmap works', getline('$')) |
| 33 | vunmap <c-c> |
| 34 | set nomodified |
| 35 | endfunc |
| 36 | |
| 37 | func Test_map_langmap() |
| 38 | " langmap should not get remapped in insert mode |
| 39 | inoremap { FAIL_ilangmap |
| 40 | set langmap=+{ langnoremap |
| 41 | call feedkeys("Go+\<Esc>", "xt") |
| 42 | call assert_equal('+', getline('$')) |
| 43 | |
| 44 | " Insert-mode expr mapping with langmap |
| 45 | inoremap <expr> { "FAIL_iexplangmap" |
| 46 | call feedkeys("Go+\<Esc>", "xt") |
| 47 | call assert_equal('+', getline('$')) |
| 48 | iunmap <expr> { |
| 49 | |
| 50 | " langmap should not get remapped in Command-line mode |
| 51 | cnoremap { FAIL_clangmap |
| 52 | call feedkeys(":call append(line('$'), '+')\<CR>", "xt") |
| 53 | call assert_equal('+', getline('$')) |
| 54 | cunmap { |
| 55 | |
| 56 | " Command-line mode expr mapping with langmap |
| 57 | cnoremap <expr> { "FAIL_cexplangmap" |
| 58 | call feedkeys(":call append(line('$'), '+')\<CR>", "xt") |
| 59 | call assert_equal('+', getline('$')) |
| 60 | cunmap { |
| 61 | set nomodified |
| 62 | endfunc |
| 63 | |
| 64 | func Test_map_feedkeys() |
| 65 | " issue #212 (feedkeys insert mapping at current position) |
| 66 | nnoremap . :call feedkeys(".", "in")<cr> |
| 67 | call setline('$', ['a b c d', 'a b c d']) |
| 68 | $-1 |
| 69 | call feedkeys("0qqdw.ifoo\<Esc>qj0@q\<Esc>", "xt") |
| 70 | call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$'))) |
| 71 | unmap . |
| 72 | set nomodified |
| 73 | endfunc |
| 74 | |
| 75 | func Test_map_cursor() |
| 76 | " <c-g>U<cursor> works only within a single line |
| 77 | imapclear |
| 78 | imap ( ()<c-g>U<left> |
| 79 | call feedkeys("G2o\<Esc>ki\<CR>Test1: text with a (here some more text\<Esc>k.", "xt") |
| 80 | call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 2)) |
| 81 | call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 1)) |
| 82 | |
| 83 | " test undo |
| 84 | call feedkeys("G2o\<Esc>ki\<CR>Test2: text wit a (here some more text [und undo]\<C-G>u\<Esc>k.u", "xt") |
| 85 | call assert_equal('', getline(line('$') - 2)) |
| 86 | call assert_equal('Test2: text wit a (here some more text [und undo])', getline(line('$') - 1)) |
| 87 | set nomodified |
| 88 | imapclear |
| 89 | endfunc |
| 90 | |
| 91 | " This isn't actually testing a mapping, but similar use of CTRL-G U as above. |
| 92 | func Test_break_undo() |
| 93 | :set whichwrap=<,>,[,] |
| 94 | call feedkeys("G4o2k", "xt") |
| 95 | exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>." |
| 96 | call assert_equal('new line here', getline(line('$') - 3)) |
| 97 | call assert_equal('Test3: text with a (parenthesis here', getline(line('$') - 2)) |
| 98 | call assert_equal('new line here', getline(line('$') - 1)) |
| 99 | set nomodified |
| 100 | endfunc |
Bram Moolenaar | 35a4cfa | 2016-08-14 16:07:48 +0200 | [diff] [blame] | 101 | |
| 102 | func Test_map_meta_quotes() |
| 103 | imap <M-"> foo |
| 104 | call feedkeys("Go-\<M-\">-\<Esc>", "xt") |
| 105 | call assert_equal("-foo-", getline('$')) |
| 106 | set nomodified |
| 107 | iunmap <M-"> |
| 108 | endfunc |