blob: ab02a87e10cda8c143ff07619dbd61c37b178eaa [file] [log] [blame]
Bram Moolenaar2d1a2482016-08-14 15:32:11 +02001" Tests for mappings and abbreviations
2
3if !has('multi_byte')
4 finish
5endif
6
7func 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
14endfunc
15
16func 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
26endfunc
27
28func 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
35endfunc
36
37func Test_map_langmap()
Bram Moolenaar920694c2016-08-21 17:45:02 +020038 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 Moolenaarda9ce2c2016-09-02 19:34:10 +020075 " 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 Moolenaar920694c2016-08-21 17:45:02 +020083 " 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 Moolenaar2d1a2482016-08-14 15:32:11 +020088 call feedkeys("Go+\<Esc>", "xt")
89 call assert_equal('+', getline('$'))
90
Bram Moolenaar920694c2016-08-21 17:45:02 +020091 " 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 Moolenaar2d1a2482016-08-14 15:32:11 +0200110 call feedkeys(":call append(line('$'), '+')\<CR>", "xt")
111 call assert_equal('+', getline('$'))
Bram Moolenaar2d1a2482016-08-14 15:32:11 +0200112
Bram Moolenaare90858d2017-02-01 17:24:34 +0100113 iunmap a
114 iunmap c
Bram Moolenaar2d1a2482016-08-14 15:32:11 +0200115 set nomodified
116endfunc
117
118func 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 Moolenaare90858d2017-02-01 17:24:34 +0100125 nunmap .
Bram Moolenaar2d1a2482016-08-14 15:32:11 +0200126 set nomodified
127endfunc
128
129func 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
143endfunc
144
145" This isn't actually testing a mapping, but similar use of CTRL-G U as above.
146func 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
154endfunc
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +0200155
156func 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-">
162endfunc
Bram Moolenaar878c2632017-04-01 15:15:52 +0200163
164func 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&
173endfunc