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() |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 38 | if !has('langmap') |
| 39 | return |
| 40 | endif |
| 41 | |
| 42 | " check langmap applies in normal mode |
| 43 | set langmap=+- nolangremap |
| 44 | new |
| 45 | call setline(1, ['a', 'b', 'c']) |
| 46 | 2 |
| 47 | call assert_equal('b', getline('.')) |
| 48 | call feedkeys("+", "xt") |
| 49 | call assert_equal('a', getline('.')) |
| 50 | |
| 51 | " check no remapping |
| 52 | map x + |
| 53 | 2 |
| 54 | call feedkeys("x", "xt") |
| 55 | call assert_equal('c', getline('.')) |
| 56 | |
| 57 | " check with remapping |
| 58 | set langremap |
| 59 | 2 |
| 60 | call feedkeys("x", "xt") |
| 61 | call assert_equal('a', getline('.')) |
| 62 | |
| 63 | unmap x |
| 64 | bwipe! |
| 65 | |
| 66 | " 'langnoremap' follows 'langremap' and vise versa |
| 67 | set langremap |
| 68 | set langnoremap |
| 69 | call assert_equal(0, &langremap) |
| 70 | set langremap |
| 71 | call assert_equal(0, &langnoremap) |
| 72 | set nolangremap |
| 73 | call assert_equal(1, &langnoremap) |
| 74 | |
Bram Moolenaar | da9ce2c | 2016-09-02 19:34:10 +0200 | [diff] [blame] | 75 | " check default values |
| 76 | set langnoremap& |
| 77 | call assert_equal(0, &langnoremap) |
| 78 | call assert_equal(1, &langremap) |
| 79 | set langremap& |
| 80 | call assert_equal(0, &langnoremap) |
| 81 | call assert_equal(1, &langremap) |
| 82 | |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 83 | " langmap should not apply in insert mode, 'langremap' doesn't matter |
| 84 | set langmap=+{ nolangremap |
| 85 | call feedkeys("Go+\<Esc>", "xt") |
| 86 | call assert_equal('+', getline('$')) |
| 87 | set langmap=+{ langremap |
Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 88 | call feedkeys("Go+\<Esc>", "xt") |
| 89 | call assert_equal('+', getline('$')) |
| 90 | |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 91 | " langmap used for register name in insert mode. |
| 92 | call setreg('a', 'aaaa') |
| 93 | call setreg('b', 'bbbb') |
| 94 | call setreg('c', 'cccc') |
| 95 | set langmap=ab langremap |
| 96 | call feedkeys("Go\<C-R>a\<Esc>", "xt") |
| 97 | call assert_equal('bbbb', getline('$')) |
| 98 | call feedkeys("Go\<C-R>\<C-R>a\<Esc>", "xt") |
| 99 | call assert_equal('bbbb', getline('$')) |
| 100 | " mapping does not apply |
| 101 | imap c a |
| 102 | call feedkeys("Go\<C-R>c\<Esc>", "xt") |
| 103 | call assert_equal('cccc', getline('$')) |
| 104 | imap a c |
| 105 | call feedkeys("Go\<C-R>a\<Esc>", "xt") |
| 106 | call assert_equal('bbbb', getline('$')) |
| 107 | |
| 108 | " langmap should not apply in Command-line mode |
| 109 | set langmap=+{ nolangremap |
Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 110 | call feedkeys(":call append(line('$'), '+')\<CR>", "xt") |
| 111 | call assert_equal('+', getline('$')) |
Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 112 | |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 113 | iunmap a |
| 114 | iunmap c |
Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 115 | set nomodified |
| 116 | endfunc |
| 117 | |
| 118 | func Test_map_feedkeys() |
| 119 | " issue #212 (feedkeys insert mapping at current position) |
| 120 | nnoremap . :call feedkeys(".", "in")<cr> |
| 121 | call setline('$', ['a b c d', 'a b c d']) |
| 122 | $-1 |
| 123 | call feedkeys("0qqdw.ifoo\<Esc>qj0@q\<Esc>", "xt") |
| 124 | call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$'))) |
Bram Moolenaar | e90858d | 2017-02-01 17:24:34 +0100 | [diff] [blame] | 125 | nunmap . |
Bram Moolenaar | 2d1a248 | 2016-08-14 15:32:11 +0200 | [diff] [blame] | 126 | set nomodified |
| 127 | endfunc |
| 128 | |
| 129 | func Test_map_cursor() |
| 130 | " <c-g>U<cursor> works only within a single line |
| 131 | imapclear |
| 132 | imap ( ()<c-g>U<left> |
| 133 | call feedkeys("G2o\<Esc>ki\<CR>Test1: text with a (here some more text\<Esc>k.", "xt") |
| 134 | call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 2)) |
| 135 | call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 1)) |
| 136 | |
| 137 | " test undo |
| 138 | call feedkeys("G2o\<Esc>ki\<CR>Test2: text wit a (here some more text [und undo]\<C-G>u\<Esc>k.u", "xt") |
| 139 | call assert_equal('', getline(line('$') - 2)) |
| 140 | call assert_equal('Test2: text wit a (here some more text [und undo])', getline(line('$') - 1)) |
| 141 | set nomodified |
| 142 | imapclear |
| 143 | endfunc |
| 144 | |
| 145 | " This isn't actually testing a mapping, but similar use of CTRL-G U as above. |
| 146 | func Test_break_undo() |
| 147 | :set whichwrap=<,>,[,] |
| 148 | call feedkeys("G4o2k", "xt") |
| 149 | exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>." |
| 150 | call assert_equal('new line here', getline(line('$') - 3)) |
| 151 | call assert_equal('Test3: text with a (parenthesis here', getline(line('$') - 2)) |
| 152 | call assert_equal('new line here', getline(line('$') - 1)) |
| 153 | set nomodified |
| 154 | endfunc |
Bram Moolenaar | 35a4cfa | 2016-08-14 16:07:48 +0200 | [diff] [blame] | 155 | |
| 156 | func Test_map_meta_quotes() |
| 157 | imap <M-"> foo |
| 158 | call feedkeys("Go-\<M-\">-\<Esc>", "xt") |
| 159 | call assert_equal("-foo-", getline('$')) |
| 160 | set nomodified |
| 161 | iunmap <M-"> |
| 162 | endfunc |
Bram Moolenaar | 878c263 | 2017-04-01 15:15:52 +0200 | [diff] [blame] | 163 | |
| 164 | func Test_abbr_after_line_join() |
| 165 | new |
| 166 | abbr foo bar |
| 167 | set backspace=indent,eol,start |
| 168 | exe "normal o\<BS>foo " |
| 169 | call assert_equal("bar ", getline(1)) |
| 170 | bwipe! |
| 171 | unabbr foo |
| 172 | set backspace& |
| 173 | endfunc |