aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/input_spec.lua
blob: ea8968a65302fb5ec7f50cbdb588cb49d19081a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
local helpers = require('test.functional.helpers')(after_each)
local clear, feed_command = helpers.clear, helpers.feed_command
local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq
local command = helpers.command
local expect = helpers.expect
local meths = helpers.meths
local exec_lua = helpers.exec_lua
local write_file = helpers.write_file
local Screen = require('test.functional.ui.screen')

before_each(clear)

describe('mappings', function()
  local add_mapping = function(mapping, send)
    local cmd = "nnoremap "..mapping.." :call rpcnotify(1, 'mapped', '"
                ..send:gsub('<', '<lt>').."')<cr>"
    feed_command(cmd)
  end

  local check_mapping = function(mapping, expected)
    feed(mapping)
    eq({'notification', 'mapped', {expected}}, next_msg())
  end

  before_each(function()
    add_mapping('<C-L>', '<C-L>')
    add_mapping('<C-S-L>', '<C-S-L>')
    add_mapping('<s-up>', '<s-up>')
    add_mapping('<s-up>', '<s-up>')
    add_mapping('<c-s-up>', '<c-s-up>')
    add_mapping('<c-s-a-up>', '<c-s-a-up>')
    add_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
    add_mapping('<c-d-a>', '<c-d-a>')
    add_mapping('<d-1>', '<d-1>')
    add_mapping('<khome>','<khome>')
    add_mapping('<kup>','<kup>')
    add_mapping('<kpageup>','<kpageup>')
    add_mapping('<kleft>','<kleft>')
    add_mapping('<korigin>','<korigin>')
    add_mapping('<kright>','<kright>')
    add_mapping('<kend>','<kend>')
    add_mapping('<kdown>','<kdown>')
    add_mapping('<kpagedown>','<kpagedown>')
    add_mapping('<kinsert>','<kinsert>')
    add_mapping('<kdel>','<kdel>')
    add_mapping('<kdivide>','<kdivide>')
    add_mapping('<kmultiply>','<kmultiply>')
    add_mapping('<kminus>','<kminus>')
    add_mapping('<kplus>','<kplus>')
    add_mapping('<kenter>','<kenter>')
    add_mapping('<kcomma>','<kcomma>')
    add_mapping('<kequal>','<kequal>')
  end)

  it('ok', function()
    check_mapping('<C-L>', '<C-L>')
    check_mapping('<C-S-L>', '<C-S-L>')
    check_mapping('<s-up>', '<s-up>')
    check_mapping('<c-s-up>', '<c-s-up>')
    check_mapping('<s-c-up>', '<c-s-up>')
    check_mapping('<c-s-a-up>', '<c-s-a-up>')
    check_mapping('<s-c-a-up>', '<c-s-a-up>')
    check_mapping('<c-a-s-up>', '<c-s-a-up>')
    check_mapping('<s-a-c-up>', '<c-s-a-up>')
    check_mapping('<a-c-s-up>', '<c-s-a-up>')
    check_mapping('<a-s-c-up>', '<c-s-a-up>')
    check_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
    check_mapping('<s-a-d-c-up>', '<c-s-a-d-up>')
    check_mapping('<d-s-a-c-up>', '<c-s-a-d-up>')
    check_mapping('<c-d-a>', '<c-d-a>')
    check_mapping('<d-c-a>', '<c-d-a>')
    check_mapping('<d-1>', '<d-1>')
    check_mapping('<khome>','<khome>')
    check_mapping('<KP7>','<khome>')
    check_mapping('<kup>','<kup>')
    check_mapping('<KP8>','<kup>')
    check_mapping('<kpageup>','<kpageup>')
    check_mapping('<KP9>','<kpageup>')
    check_mapping('<kleft>','<kleft>')
    check_mapping('<KP4>','<kleft>')
    check_mapping('<korigin>','<korigin>')
    check_mapping('<KP5>','<korigin>')
    check_mapping('<kright>','<kright>')
    check_mapping('<KP6>','<kright>')
    check_mapping('<kend>','<kend>')
    check_mapping('<KP1>','<kend>')
    check_mapping('<kdown>','<kdown>')
    check_mapping('<KP2>','<kdown>')
    check_mapping('<kpagedown>','<kpagedown>')
    check_mapping('<KP3>','<kpagedown>')
    check_mapping('<kinsert>','<kinsert>')
    check_mapping('<KP0>','<kinsert>')
    check_mapping('<kdel>','<kdel>')
    check_mapping('<KPPeriod>','<kdel>')
    check_mapping('<kdivide>','<kdivide>')
    check_mapping('<KPDiv>','<kdivide>')
    check_mapping('<kmultiply>','<kmultiply>')
    check_mapping('<KPMult>','<kmultiply>')
    check_mapping('<kminus>','<kminus>')
    check_mapping('<KPMinus>','<kminus>')
    check_mapping('<kplus>','<kplus>')
    check_mapping('<KPPlus>','<kplus>')
    check_mapping('<kenter>','<kenter>')
    check_mapping('<KPEnter>','<kenter>')
    check_mapping('<kcomma>','<kcomma>')
    check_mapping('<KPComma>','<kcomma>')
    check_mapping('<kequal>','<kequal>')
    check_mapping('<KPEquals>','<kequal>')
  end)

  it('support meta + multibyte char mapping', function()
    add_mapping('<m-ä>', '<m-ä>')
    check_mapping('<m-ä>', '<m-ä>')
  end)
end)

describe('input utf sequences that contain CSI/K_SPECIAL', function()
  it('ok', function()
    feed('i…<esc>')
    expect('…')
  end)
end)

describe('input non-printable chars', function()
  after_each(function()
    os.remove('Xtest-overwrite')
  end)

  it("doesn't crash when echoing them back", function()
    write_file("Xtest-overwrite", [[foobar]])
    local screen = Screen.new(60,8)
    screen:set_default_attr_ids({
      [1] = {bold = true, foreground = Screen.colors.Blue1},
      [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
      [3] = {bold = true, foreground = Screen.colors.SeaGreen4}
    })
    screen:attach()
    command("set display-=msgsep shortmess-=F")

    feed_command("e Xtest-overwrite")
    screen:expect([[
      ^foobar                                                      |
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      "Xtest-overwrite" [noeol] 1L, 6C                            |
    ]])

    -- The timestamp is in second resolution, wait two seconds to be sure.
    screen:sleep(2000)
    write_file("Xtest-overwrite", [[smurf]])
    feed_command("w")
    screen:expect([[
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      "Xtest-overwrite"                                           |
      {2:WARNING: The file has been changed since reading it!!!}      |
      {3:Do you really want to write to it (y/n)?}^                    |
    ]])

    feed("u")
    screen:expect([[
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      "Xtest-overwrite"                                           |
      {2:WARNING: The file has been changed since reading it!!!}      |
      {3:Do you really want to write to it (y/n)?}u                   |
      {3:Do you really want to write to it (y/n)?}^                    |
    ]])

    feed("\005")
    screen:expect([[
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      "Xtest-overwrite"                                           |
      {2:WARNING: The file has been changed since reading it!!!}      |
      {3:Do you really want to write to it (y/n)?}u                   |
      {3:Do you really want to write to it (y/n)?}                    |
      {3:Do you really want to write to it (y/n)?}^                    |
    ]])

    feed("n")
    screen:expect([[
      {1:~                                                           }|
      {1:~                                                           }|
      "Xtest-overwrite"                                           |
      {2:WARNING: The file has been changed since reading it!!!}      |
      {3:Do you really want to write to it (y/n)?}u                   |
      {3:Do you really want to write to it (y/n)?}                    |
      {3:Do you really want to write to it (y/n)?}n                   |
      {3:Press ENTER or type command to continue}^                     |
    ]])

    feed("<cr>")
    screen:expect([[
      ^foobar                                                      |
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
      {1:~                                                           }|
                                                                  |
    ]])
  end)
end)

describe("event processing and input", function()
  it('not blocked by event bursts', function()
    meths.set_keymap('', '<f2>', "<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>", {noremap=true})

    exec_lua [[
      winning = false
      burst = vim.schedule_wrap(function(tell)
        if tell then
          vim.rpcnotify(1, 'start')
        end
        -- Are we winning, son?
        if not winning then
          burst(false)
        end
      end)
      burst(true)
    ]]

    eq({'notification', 'start', {}}, next_msg())
    feed '<f2>'
    eq({'notification', 'stop', {}}, next_msg())
  end)
end)