Bram Moolenaar | 2528163 | 2016-01-21 23:32:32 +0100 | [diff] [blame] | 1 | " tests for 'langmap' |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | CheckFeature langmap |
Bram Moolenaar | 09e786e | 2016-01-21 23:53:06 +0100 | [diff] [blame] | 4 | |
Bram Moolenaar | 2528163 | 2016-01-21 23:32:32 +0100 | [diff] [blame] | 5 | func Test_langmap() |
| 6 | new |
| 7 | set langmap=}l,^x,%v |
| 8 | |
| 9 | call setline(1, ['abc']) |
| 10 | call feedkeys('gg0}^', 'tx') |
| 11 | call assert_equal('ac', getline(1)) |
| 12 | |
| 13 | " in Replace mode |
| 14 | " need silent! to avoid a delay when entering Insert mode |
| 15 | call setline(1, ['abcde']) |
| 16 | silent! call feedkeys("gg0lR%{z\<Esc>00", 'tx') |
| 17 | call assert_equal('a%{ze', getline(1)) |
| 18 | |
| 19 | " in Select mode |
| 20 | " need silent! to avoid a delay when entering Insert mode |
| 21 | call setline(1, ['abcde']) |
| 22 | silent! call feedkeys("gg0}%}\<C-G>}^\<Esc>00", 'tx') |
| 23 | call assert_equal('a}^de', getline(1)) |
| 24 | |
Bram Moolenaar | c2a60ae | 2020-01-23 16:19:54 +0100 | [diff] [blame] | 25 | " Error cases |
| 26 | call assert_fails('set langmap=aA,b', 'E357:') |
| 27 | call assert_fails('set langmap=z;y;y;z', 'E358:') |
| 28 | |
| 29 | " Map character > 256 |
| 30 | enew! |
| 31 | set langmap=āx,ăl,āx |
| 32 | call setline(1, ['abcde']) |
| 33 | call feedkeys('gg2lā', 'tx') |
| 34 | call assert_equal('abde', getline(1)) |
| 35 | |
| 36 | " special characters in langmap |
| 37 | enew! |
| 38 | call setline(1, ['Hello World']) |
| 39 | set langmap=\\;\\,,\\,\\; |
| 40 | call feedkeys('ggfo,', 'tx') |
| 41 | call assert_equal(8, col('.')) |
| 42 | call feedkeys(';', 'tx') |
| 43 | call assert_equal(5, col('.')) |
| 44 | set langmap& |
| 45 | set langmap=\\;\\,;\\,\\; |
| 46 | call feedkeys('ggfo,', 'tx') |
| 47 | call assert_equal(8, col('.')) |
| 48 | call feedkeys(';', 'tx') |
| 49 | call assert_equal(5, col('.')) |
| 50 | |
zeertzjq | 49660f5 | 2022-10-20 17:59:38 +0100 | [diff] [blame] | 51 | set langmap=RL |
| 52 | let g:counter = 0 |
| 53 | nnoremap L;L <Cmd>let g:counter += 1<CR> |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 54 | nnoremap <C-L> <Cmd>throw 'This mapping should not be triggered'<CR> |
zeertzjq | 49660f5 | 2022-10-20 17:59:38 +0100 | [diff] [blame] | 55 | |
| 56 | " 'langmap' is applied to keys without modifiers when matching a mapping |
| 57 | call feedkeys('R;R', 'tx') |
| 58 | call assert_equal(1, g:counter) |
| 59 | nunmap L;L |
| 60 | unlet g:counter |
| 61 | |
| 62 | delete |
| 63 | call assert_equal('', getline(1)) |
| 64 | undo |
| 65 | call assert_equal('Hello World', getline(1)) |
| 66 | " 'langmap' does not change Ctrl-R to Ctrl-L for consistency |
| 67 | call feedkeys("\<*C-R>", 'tx') |
| 68 | call assert_equal('', getline(1)) |
| 69 | |
| 70 | set langmap=6L |
| 71 | undo |
| 72 | setlocal bufhidden=hide |
| 73 | let oldbuf = bufnr() |
| 74 | enew |
| 75 | call assert_notequal(oldbuf, bufnr()) |
| 76 | " 'langmap' does not change Ctrl-6 to Ctrl-L for consistency |
| 77 | " Ctrl-6 becomes Ctrl-^ after merging the Ctrl modifier |
| 78 | call feedkeys("\<*C-6>", 'tx') |
| 79 | call assert_equal(oldbuf, bufnr()) |
| 80 | setlocal bufhidden& |
| 81 | |
| 82 | nunmap <C-L> |
| 83 | |
Bram Moolenaar | c2a60ae | 2020-01-23 16:19:54 +0100 | [diff] [blame] | 84 | set langmap& |
Bram Moolenaar | 2528163 | 2016-01-21 23:32:32 +0100 | [diff] [blame] | 85 | quit! |
| 86 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 87 | |
| 88 | " vim: shiftwidth=2 sts=2 expandtab |