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