robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfeat(input)!: CmdAtom event #4129764a301184e

master
7.4 KiB255 linesraw
1-- Test for mappings and abbreviations
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local clear, feed, insert = n.clear, n.feed, n.insert
9local expect, poke_eventloop = n.expect, n.poke_eventloop
10local command, eq, eval, api = n.command, t.eq, n.eval, n.api
11local exec = n.exec
12local sleep = vim.uv.sleep
13
14describe('mapping', function()
15  before_each(clear)
16
17  it('abbreviations with р (0x80)', function()
18    insert([[
19      test starts here:
20      ]])
21
22    -- Abbreviations with р (0x80) should work.
23    command('inoreab чкпр   vim')
24    feed('GAчкпр <esc>')
25
26    expect([[
27      test starts here:
28      vim ]])
29  end)
30
31  -- oldtest: Test_map_ctrl_c_insert()
32  it('Ctrl-c works in Insert mode', function()
33    -- Mapping of ctrl-c in insert mode
34    command('set cpo-=< cpo-=k')
35    command('inoremap <c-c> <ctrl-c>')
36    command('cnoremap <c-c> dummy')
37    command('cunmap <c-c>')
38    feed('GA<cr>')
39    -- XXX: editor must be in Insert mode before <C-C> is put into input buffer
40    poke_eventloop()
41    feed('TEST2: CTRL-C |<c-c>A|<cr><esc>')
42    command('unmap! <c-c>')
43
44    expect([[
45
46      TEST2: CTRL-C |<ctrl-c>A|
47      ]])
48  end)
49
50  -- oldtest: Test_map_ctrl_c_visual()
51  it('Ctrl-c works in Visual mode', function()
52    command([[vnoremap <c-c> :<C-u>$put ='vmap works'<cr>]])
53    feed('GV')
54    -- XXX: editor must be in Visual mode before <C-C> is put into input buffer
55    poke_eventloop()
56    feed('vV<c-c>')
57    command('vunmap <c-c>')
58
59    expect([[
60
61      vmap works]])
62  end)
63
64  it('langmap', function()
65    -- langmap should not get remapped in insert mode.
66    command('inoremap { FAIL_ilangmap')
67    command('set langmap=+{ langnoremap')
68    feed('o+<esc>')
69
70    -- Insert mode expr mapping with langmap.
71    command('inoremap <expr> { "FAIL_iexplangmap"')
72    feed('o+<esc>')
73
74    -- langmap should not get remapped in cmdline mode.
75    command('cnoremap { FAIL_clangmap')
76    feed('o+<esc>')
77    command('cunmap {')
78
79    -- cmdline mode expr mapping with langmap.
80    command('cnoremap <expr> { "FAIL_cexplangmap"')
81    feed('o+<esc>')
82    command('cunmap {')
83
84    -- Assert buffer contents.
85    expect([[
86
87      +
88      +
89      +
90      +]])
91  end)
92
93  -- oldtest: Test_map_feedkeys()
94  it('feedkeys', function()
95    insert([[
96      a b c d
97      a b c d
98      ]])
99
100    -- Vim's issue #212 (feedkeys insert mapping at current position)
101    command('nnoremap . :call feedkeys(".", "in")<cr>')
102    feed('/^a b<cr>')
103    feed('0qqdw.ifoo<esc>qj0@q<esc>')
104    command('unmap .')
105    expect([[
106      fooc d
107      fooc d
108      ]])
109  end)
110
111  -- oldtest: Test_map_cursor()
112  it('i_CTRL-G_U', function()
113    -- <c-g>U<cursor> works only within a single line
114    command('imapclear')
115    command('imap ( ()<c-g>U<left>')
116    feed('G2o<esc>ki<cr>Test1: text with a (here some more text<esc>k.')
117    -- test undo
118    feed('G2o<esc>ki<cr>Test2: text wit a (here some more text [und undo]<c-g>u<esc>k.u')
119    command('imapclear')
120    command('set whichwrap=<,>,[,]')
121    feed('G3o<esc>2k')
122    -- Nvim: "." re-executes the whole insert session, including the (wrapping)
123    -- CTRL-G U <Right>, instead of only the text typed after it.
124    command(
125      [[:exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."]]
126    )
127
128    expect([[
129
130
131      Test1: text with a (here some more text)
132      Test1: text with a (here some more text)
133
134
135      Test2: text wit a (here some more text [und undo])
136      Test3: text with a (parenthesis here
137      new line hereTest3: text with a (parenthesis here
138      new line here
139      ]])
140  end)
141
142  -- oldtest: Test_mouse_drag_mapped_start_select()
143  it('dragging starts Select mode even if coming from mapping', function()
144    command('set mouse=a')
145    command('set selectmode=mouse')
146
147    command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>')
148    poke_eventloop()
149    api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
150    poke_eventloop()
151    api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
152    poke_eventloop()
153    eq('s', eval('mode()'))
154  end)
155
156  -- oldtest: Test_mouse_drag_insert_map()
157  it('<LeftDrag> mapping in Insert mode works correctly', function()
158    command('set mouse=a')
159
160    command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>')
161    feed('i')
162    poke_eventloop()
163    api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
164    poke_eventloop()
165    api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
166    poke_eventloop()
167    eq(1, eval('g:dragged'))
168    eq('v', eval('mode()'))
169    feed([[<C-\><C-N>]])
170
171    command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]])
172    feed('i')
173    poke_eventloop()
174    api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
175    poke_eventloop()
176    api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
177    poke_eventloop()
178    eq('n', eval('mode()'))
179  end)
180
181  -- oldtest: Test_map_after_timed_out_nop()
182  it('timeout works after an <Nop> mapping is triggered on timeout', function()
183    command('set timeout timeoutlen=400')
184    command('inoremap ab TEST')
185    command('inoremap a <Nop>')
186    -- Enter Insert mode
187    feed('i')
188    -- Wait for the "a" mapping to time out
189    feed('a')
190    sleep(500)
191    -- Send "a" and wait for a period shorter than 'timeoutlen'
192    feed('a')
193    sleep(100)
194    -- Send "b", should trigger the "ab" mapping
195    feed('b')
196    expect('TEST')
197  end)
198
199  -- oldtest: Test_showcmd_part_map()
200  it("'showcmd' with a partial mapping", function()
201    local screen = Screen.new(60, 6)
202    exec([[
203      set notimeout showcmd
204      nnoremap ,a <Ignore>
205      nnoremap ;a <Ignore>
206      nnoremap Àa <Ignore>
207      nnoremap Ëa <Ignore>
208      nnoremap βa <Ignore>
209      nnoremap ωa <Ignore>
210      nnoremap …a <Ignore>
211      nnoremap <C-W>a <Ignore>
212    ]])
213
214    for _, c in ipairs({ ',', ';', 'À', 'Ë', 'β', 'ω', '…' }) do
215      feed(c)
216      screen:expect(([[
217        ^                                                            |
218        {1:~                                                           }|*4
219                                                         %s          |
220      ]]):format(c))
221      feed('a')
222      screen:expect([[
223        ^                                                            |
224        {1:~                                                           }|*4
225                                                                    |
226      ]])
227    end
228
229    feed('\23')
230    screen:expect([[
231      ^                                                            |
232      {1:~                                                           }|*4
233                                                       ^W         |
234    ]])
235    feed('a')
236    screen:expect([[
237      ^                                                            |
238      {1:~                                                           }|*4
239                                                                  |
240    ]])
241
242    feed('<C-W>')
243    screen:expect([[
244      ^                                                            |
245      {1:~                                                           }|*4
246                                                       ^W         |
247    ]])
248    feed('a')
249    screen:expect([[
250      ^                                                            |
251      {1:~                                                           }|*4
252                                                                  |
253    ]])
254  end)
255end)