blob: 4a8427732b617de2d635f7e9a62c5a059e1e7eb9 [file] [log] [blame]
Bram Moolenaar25281632016-01-21 23:32:32 +01001" tests for 'langmap'
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003CheckFeature langmap
Bram Moolenaar09e786e2016-01-21 23:53:06 +01004
Bram Moolenaar25281632016-01-21 23:32:32 +01005func 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 Moolenaarc2a60ae2020-01-23 16:19:54 +010025 " 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
zeertzjq49660f52022-10-20 17:59:38 +010051 set langmap=RL
52 let g:counter = 0
53 nnoremap L;L <Cmd>let g:counter += 1<CR>
dundargocc57b5bc2022-11-02 13:30:51 +000054 nnoremap <C-L> <Cmd>throw 'This mapping should not be triggered'<CR>
zeertzjq49660f52022-10-20 17:59:38 +010055
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 Moolenaarc2a60ae2020-01-23 16:19:54 +010084 set langmap&
Bram Moolenaar25281632016-01-21 23:32:32 +010085 quit!
86endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020087
88" vim: shiftwidth=2 sts=2 expandtab