robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
6.5 KiB238 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, pending = t.describe, t.it, t.before_each, t.pending
5local clear, feed, eq = n.clear, n.feed, t.eq
6local expect, command, eval = n.expect, n.command, n.eval
7local insert, call = n.insert, n.call
8local exec_capture, dedent = n.exec_capture, t.dedent
9
10-- First test it's implemented using the :lmap and :lnoremap commands, then
11-- check those mappings behave as expected.
12describe("'keymap' / :lmap", function()
13  before_each(function()
14    clear()
15    insert('lllaaa')
16    command('set iminsert=1')
17    command('set imsearch=1')
18    command('lmap l a')
19    feed('gg0')
20  end)
21
22  describe("'keymap' as :lmap", function()
23    -- Shows that 'keymap' sets language mappings that allows remapping.
24    -- This equivalence allows us to only test :lmap commands and assert they
25    -- behave the same as 'keymap' settings.
26    -- It does rely on the absence of special code that implements 'keymap'
27    -- and :lmap differently but shows mappings from the 'keymap' after
28    -- typing :lmap.
29    -- At the moment this is the case.
30    it("'keymap' mappings are shown with :lmap", function()
31      command('lmapclear')
32      command('lmapclear <buffer>')
33      command('set keymap=dvorak')
34      command('set nomore')
35      local bindings = exec_capture('lmap')
36      eq(
37        dedent([[
38
39      l  "            @_
40      l  '            @-
41      l  +            @}
42      l  ,            @w
43      l  -            @[
44      l  .            @v
45      l  /            @z
46      l  :            @S
47      l  ;            @s
48      l  <            @W
49      l  =            @]
50      l  >            @V
51      l  ?            @Z
52      l  A            @A
53      l  B            @X
54      l  C            @J
55      l  D            @E
56      l  E            @>
57      l  F            @U
58      l  G            @I
59      l  H            @D
60      l  I            @C
61      l  J            @H
62      l  K            @T
63      l  L            @N
64      l  M            @M
65      l  N            @B
66      l  O            @R
67      l  P            @L
68      l  Q            @"
69      l  R            @P
70      l  S            @O
71      l  T            @Y
72      l  U            @G
73      l  V            @K
74      l  W            @<
75      l  X            @Q
76      l  Y            @F
77      l  Z            @:
78      l  [            @/
79      l  \            @\
80      l  ]            @=
81      l  _            @{
82      l  a            @a
83      l  b            @x
84      l  c            @j
85      l  d            @e
86      l  e            @.
87      l  f            @u
88      l  g            @i
89      l  h            @d
90      l  i            @c
91      l  j            @h
92      l  k            @t
93      l  l            @n
94      l  m            @m
95      l  n            @b
96      l  o            @r
97      l  p            @l
98      l  q            @'
99      l  r            @p
100      l  s            @o
101      l  t            @y
102      l  u            @g
103      l  v            @k
104      l  w            @,
105      l  x            @q
106      l  y            @f
107      l  z            @;
108      l  {            @?
109      l  |            @|
110      l  }            @+]]),
111        bindings
112      )
113    end)
114  end)
115  describe("'iminsert' option", function()
116    it('Uses :lmap in insert mode when ON', function()
117      feed('il<esc>')
118      expect('alllaaa')
119    end)
120    it('Ignores :lmap in insert mode when OFF', function()
121      command('set iminsert=0')
122      feed('il<esc>')
123      expect('llllaaa')
124    end)
125    it('Can be toggled with <C-^> in insert mode', function()
126      feed('i<C-^>l<C-^>l<esc>')
127      expect('lalllaaa')
128      eq(1, eval('&iminsert'))
129      feed('i<C-^><esc>')
130      eq(0, eval('&iminsert'))
131    end)
132  end)
133  describe("'imsearch' option", function()
134    it('Uses :lmap at search prompt when ON', function()
135      feed('/lll<cr>3x')
136      expect('lll')
137    end)
138    it('Ignores :lmap at search prompt when OFF', function()
139      command('set imsearch=0')
140      feed('gg/lll<cr>3x')
141      expect('aaa')
142    end)
143    it('Can be toggled with C-^', function()
144      eq(1, eval('&imsearch'))
145      feed('/<C-^>lll<cr>3x')
146      expect('aaa')
147      eq(0, eval('&imsearch'))
148      feed('u0/<C-^>lll<cr>3x')
149      expect('lll')
150      eq(1, eval('&imsearch'))
151    end)
152    it("can follow 'iminsert'", function()
153      command('set imsearch=-1')
154      feed('/lll<cr>3x')
155      expect('lll')
156      eq(-1, eval('&imsearch'))
157      eq(1, eval('&iminsert'))
158      feed('u/<C-^>lll<cr>3x')
159      expect('aaa')
160      eq(-1, eval('&imsearch'))
161      eq(0, eval('&iminsert'))
162    end)
163  end)
164  it(':lmap not applied to macros', function()
165    command("call setreg('a', 'il')")
166    feed('@a')
167    expect('llllaaa')
168    eq('il', call('getreg', 'a'))
169  end)
170  it(':lmap applied to macro recording', function()
171    feed('qail<esc>q@a')
172    expect('aalllaaa')
173    eq('ia', call('getreg', 'a'))
174  end)
175  it(':lmap not applied to mappings', function()
176    command('imap t l')
177    feed('it<esc>')
178    expect('llllaaa')
179  end)
180  it('mappings applied to keys created with :lmap', function()
181    command('imap a x')
182    feed('il<esc>')
183    expect('xlllaaa')
184  end)
185  it('mappings not applied to keys gotten with :lnoremap', function()
186    command('lmapclear')
187    command('lnoremap l a')
188    command('imap a x')
189    feed('il<esc>')
190    expect('alllaaa')
191  end)
192  -- This is a problem introduced when introducing :lmap and macro
193  -- compatibility. There are no plans to fix this as the complexity involved
194  -- seems too great.
195  pending('mappings not applied to macro replay of :lnoremap', function()
196    command('lmapclear')
197    command('lnoremap l a')
198    command('imap a x')
199    feed('qail<esc>q')
200    expect('alllaaa')
201    feed('@a')
202    expect('aalllaaa')
203  end)
204  it('is applied when using f/F t/T', function()
205    feed('flx')
206    expect('lllaa')
207    feed('0ia<esc>4lFlx')
208    expect('lllaa')
209    feed('tllx')
210    expect('llla')
211    feed('0ia<esc>4lTlhx')
212    expect('llla')
213  end)
214  it('takes priority over :imap mappings', function()
215    command('imap l x')
216    feed('il<esc>')
217    expect('alllaaa')
218    command('lmapclear')
219    command('lmap l a')
220    feed('il')
221    expect('aalllaaa')
222  end)
223  it('does not cause recursive mappings', function()
224    command('lmap a l')
225    feed('qaila<esc>q')
226    expect('allllaaa')
227    feed('u@a')
228    expect('allllaaa')
229  end)
230  it('can handle multicharacter mappings', function()
231    command("lmap 'a x")
232    command("lmap '' '")
233    feed("qai'a''a<esc>q")
234    expect("x'alllaaa")
235    feed('u@a')
236    expect("x'alllaaa")
237  end)
238end)