input_spec.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear, feed_command = helpers.clear, helpers.feed_command
  3. local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq
  4. local command = helpers.command
  5. local expect = helpers.expect
  6. local meths = helpers.meths
  7. local exec_lua = helpers.exec_lua
  8. local write_file = helpers.write_file
  9. local Screen = require('test.functional.ui.screen')
  10. before_each(clear)
  11. describe('mappings', function()
  12. local add_mapping = function(mapping, send)
  13. local cmd = "nnoremap "..mapping.." :call rpcnotify(1, 'mapped', '"
  14. ..send:gsub('<', '<lt>').."')<cr>"
  15. feed_command(cmd)
  16. end
  17. local check_mapping = function(mapping, expected)
  18. feed(mapping)
  19. eq({'notification', 'mapped', {expected}}, next_msg())
  20. end
  21. before_each(function()
  22. add_mapping('<C-L>', '<C-L>')
  23. add_mapping('<C-S-L>', '<C-S-L>')
  24. add_mapping('<s-up>', '<s-up>')
  25. add_mapping('<s-up>', '<s-up>')
  26. add_mapping('<c-s-up>', '<c-s-up>')
  27. add_mapping('<c-s-a-up>', '<c-s-a-up>')
  28. add_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
  29. add_mapping('<c-d-a>', '<c-d-a>')
  30. add_mapping('<d-1>', '<d-1>')
  31. add_mapping('<khome>','<khome>')
  32. add_mapping('<kup>','<kup>')
  33. add_mapping('<kpageup>','<kpageup>')
  34. add_mapping('<kleft>','<kleft>')
  35. add_mapping('<korigin>','<korigin>')
  36. add_mapping('<kright>','<kright>')
  37. add_mapping('<kend>','<kend>')
  38. add_mapping('<kdown>','<kdown>')
  39. add_mapping('<kpagedown>','<kpagedown>')
  40. add_mapping('<kinsert>','<kinsert>')
  41. add_mapping('<kdel>','<kdel>')
  42. add_mapping('<kdivide>','<kdivide>')
  43. add_mapping('<kmultiply>','<kmultiply>')
  44. add_mapping('<kminus>','<kminus>')
  45. add_mapping('<kplus>','<kplus>')
  46. add_mapping('<kenter>','<kenter>')
  47. add_mapping('<kcomma>','<kcomma>')
  48. add_mapping('<kequal>','<kequal>')
  49. end)
  50. it('ok', function()
  51. check_mapping('<C-L>', '<C-L>')
  52. check_mapping('<C-S-L>', '<C-S-L>')
  53. check_mapping('<s-up>', '<s-up>')
  54. check_mapping('<c-s-up>', '<c-s-up>')
  55. check_mapping('<s-c-up>', '<c-s-up>')
  56. check_mapping('<c-s-a-up>', '<c-s-a-up>')
  57. check_mapping('<s-c-a-up>', '<c-s-a-up>')
  58. check_mapping('<c-a-s-up>', '<c-s-a-up>')
  59. check_mapping('<s-a-c-up>', '<c-s-a-up>')
  60. check_mapping('<a-c-s-up>', '<c-s-a-up>')
  61. check_mapping('<a-s-c-up>', '<c-s-a-up>')
  62. check_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
  63. check_mapping('<s-a-d-c-up>', '<c-s-a-d-up>')
  64. check_mapping('<d-s-a-c-up>', '<c-s-a-d-up>')
  65. check_mapping('<c-d-a>', '<c-d-a>')
  66. check_mapping('<d-c-a>', '<c-d-a>')
  67. check_mapping('<d-1>', '<d-1>')
  68. check_mapping('<khome>','<khome>')
  69. check_mapping('<KP7>','<khome>')
  70. check_mapping('<kup>','<kup>')
  71. check_mapping('<KP8>','<kup>')
  72. check_mapping('<kpageup>','<kpageup>')
  73. check_mapping('<KP9>','<kpageup>')
  74. check_mapping('<kleft>','<kleft>')
  75. check_mapping('<KP4>','<kleft>')
  76. check_mapping('<korigin>','<korigin>')
  77. check_mapping('<KP5>','<korigin>')
  78. check_mapping('<kright>','<kright>')
  79. check_mapping('<KP6>','<kright>')
  80. check_mapping('<kend>','<kend>')
  81. check_mapping('<KP1>','<kend>')
  82. check_mapping('<kdown>','<kdown>')
  83. check_mapping('<KP2>','<kdown>')
  84. check_mapping('<kpagedown>','<kpagedown>')
  85. check_mapping('<KP3>','<kpagedown>')
  86. check_mapping('<kinsert>','<kinsert>')
  87. check_mapping('<KP0>','<kinsert>')
  88. check_mapping('<kdel>','<kdel>')
  89. check_mapping('<KPPeriod>','<kdel>')
  90. check_mapping('<kdivide>','<kdivide>')
  91. check_mapping('<KPDiv>','<kdivide>')
  92. check_mapping('<kmultiply>','<kmultiply>')
  93. check_mapping('<KPMult>','<kmultiply>')
  94. check_mapping('<kminus>','<kminus>')
  95. check_mapping('<KPMinus>','<kminus>')
  96. check_mapping('<kplus>','<kplus>')
  97. check_mapping('<KPPlus>','<kplus>')
  98. check_mapping('<kenter>','<kenter>')
  99. check_mapping('<KPEnter>','<kenter>')
  100. check_mapping('<kcomma>','<kcomma>')
  101. check_mapping('<KPComma>','<kcomma>')
  102. check_mapping('<kequal>','<kequal>')
  103. check_mapping('<KPEquals>','<kequal>')
  104. end)
  105. it('support meta + multibyte char mapping', function()
  106. add_mapping('<m-ä>', '<m-ä>')
  107. check_mapping('<m-ä>', '<m-ä>')
  108. end)
  109. end)
  110. describe('input utf sequences that contain CSI/K_SPECIAL', function()
  111. it('ok', function()
  112. feed('i…<esc>')
  113. expect('…')
  114. end)
  115. end)
  116. describe('input non-printable chars', function()
  117. after_each(function()
  118. os.remove('Xtest-overwrite')
  119. end)
  120. it("doesn't crash when echoing them back", function()
  121. write_file("Xtest-overwrite", [[foobar]])
  122. local screen = Screen.new(60,8)
  123. screen:set_default_attr_ids({
  124. [1] = {bold = true, foreground = Screen.colors.Blue1},
  125. [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
  126. [3] = {bold = true, foreground = Screen.colors.SeaGreen4}
  127. })
  128. screen:attach()
  129. command("set display-=msgsep shortmess-=F")
  130. feed_command("e Xtest-overwrite")
  131. screen:expect([[
  132. ^foobar |
  133. {1:~ }|
  134. {1:~ }|
  135. {1:~ }|
  136. {1:~ }|
  137. {1:~ }|
  138. {1:~ }|
  139. "Xtest-overwrite" [noeol] 1L, 6C |
  140. ]])
  141. -- The timestamp is in second resolution, wait two seconds to be sure.
  142. screen:sleep(2000)
  143. write_file("Xtest-overwrite", [[smurf]])
  144. feed_command("w")
  145. screen:expect([[
  146. {1:~ }|
  147. {1:~ }|
  148. {1:~ }|
  149. {1:~ }|
  150. {1:~ }|
  151. "Xtest-overwrite" |
  152. {2:WARNING: The file has been changed since reading it!!!} |
  153. {3:Do you really want to write to it (y/n)?}^ |
  154. ]])
  155. feed("u")
  156. screen:expect([[
  157. {1:~ }|
  158. {1:~ }|
  159. {1:~ }|
  160. {1:~ }|
  161. "Xtest-overwrite" |
  162. {2:WARNING: The file has been changed since reading it!!!} |
  163. {3:Do you really want to write to it (y/n)?}u |
  164. {3:Do you really want to write to it (y/n)?}^ |
  165. ]])
  166. feed("\005")
  167. screen:expect([[
  168. {1:~ }|
  169. {1:~ }|
  170. {1:~ }|
  171. "Xtest-overwrite" |
  172. {2:WARNING: The file has been changed since reading it!!!} |
  173. {3:Do you really want to write to it (y/n)?}u |
  174. {3:Do you really want to write to it (y/n)?} |
  175. {3:Do you really want to write to it (y/n)?}^ |
  176. ]])
  177. feed("n")
  178. screen:expect([[
  179. {1:~ }|
  180. {1:~ }|
  181. "Xtest-overwrite" |
  182. {2:WARNING: The file has been changed since reading it!!!} |
  183. {3:Do you really want to write to it (y/n)?}u |
  184. {3:Do you really want to write to it (y/n)?} |
  185. {3:Do you really want to write to it (y/n)?}n |
  186. {3:Press ENTER or type command to continue}^ |
  187. ]])
  188. feed("<cr>")
  189. screen:expect([[
  190. ^foobar |
  191. {1:~ }|
  192. {1:~ }|
  193. {1:~ }|
  194. {1:~ }|
  195. {1:~ }|
  196. {1:~ }|
  197. |
  198. ]])
  199. end)
  200. end)
  201. describe("event processing and input", function()
  202. it('not blocked by event bursts', function()
  203. meths.set_keymap('', '<f2>', "<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>", {noremap=true})
  204. exec_lua [[
  205. winning = false
  206. burst = vim.schedule_wrap(function(tell)
  207. if tell then
  208. vim.rpcnotify(1, 'start')
  209. end
  210. -- Are we winning, son?
  211. if not winning then
  212. burst(false)
  213. end
  214. end)
  215. burst(true)
  216. ]]
  217. eq({'notification', 'start', {}}, next_msg())
  218. feed '<f2>'
  219. eq({'notification', 'stop', {}}, next_msg())
  220. end)
  221. end)