input_spec.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear, feed_command, nvim = helpers.clear, helpers.feed_command, helpers.nvim
  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 write_file = helpers.write_file
  7. local Screen = require('test.functional.ui.screen')
  8. describe('mappings', function()
  9. local cid
  10. local add_mapping = function(mapping, send)
  11. local cmd = "nnoremap "..mapping.." :call rpcnotify("..cid..", 'mapped', '"
  12. ..send:gsub('<', '<lt>').."')<cr>"
  13. feed_command(cmd)
  14. end
  15. local check_mapping = function(mapping, expected)
  16. feed(mapping)
  17. eq({'notification', 'mapped', {expected}}, next_msg())
  18. end
  19. before_each(function()
  20. clear()
  21. cid = nvim('get_api_info')[1]
  22. add_mapping('<s-up>', '<s-up>')
  23. add_mapping('<s-up>', '<s-up>')
  24. add_mapping('<c-s-up>', '<c-s-up>')
  25. add_mapping('<c-s-a-up>', '<c-s-a-up>')
  26. add_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
  27. add_mapping('<c-d-a>', '<c-d-a>')
  28. add_mapping('<d-1>', '<d-1>')
  29. end)
  30. it('ok', function()
  31. check_mapping('<s-up>', '<s-up>')
  32. check_mapping('<c-s-up>', '<c-s-up>')
  33. check_mapping('<s-c-up>', '<c-s-up>')
  34. check_mapping('<c-s-a-up>', '<c-s-a-up>')
  35. check_mapping('<s-c-a-up>', '<c-s-a-up>')
  36. check_mapping('<c-a-s-up>', '<c-s-a-up>')
  37. check_mapping('<s-a-c-up>', '<c-s-a-up>')
  38. check_mapping('<a-c-s-up>', '<c-s-a-up>')
  39. check_mapping('<a-s-c-up>', '<c-s-a-up>')
  40. check_mapping('<c-s-a-d-up>', '<c-s-a-d-up>')
  41. check_mapping('<s-a-d-c-up>', '<c-s-a-d-up>')
  42. check_mapping('<d-s-a-c-up>', '<c-s-a-d-up>')
  43. check_mapping('<c-d-a>', '<c-d-a>')
  44. check_mapping('<d-c-a>', '<c-d-a>')
  45. check_mapping('<d-1>', '<d-1>')
  46. end)
  47. end)
  48. describe('feeding large chunks of input with <Paste>', function()
  49. local screen
  50. before_each(function()
  51. clear()
  52. screen = Screen.new()
  53. screen:attach()
  54. feed_command('set ruler')
  55. end)
  56. it('ok', function()
  57. if helpers.skip_fragile(pending) then
  58. return
  59. end
  60. local t = {}
  61. for i = 1, 20000 do
  62. t[i] = 'item ' .. tostring(i)
  63. end
  64. feed('i<Paste>')
  65. screen:expect([[
  66. ^ |
  67. ~ |
  68. ~ |
  69. ~ |
  70. ~ |
  71. ~ |
  72. ~ |
  73. ~ |
  74. ~ |
  75. ~ |
  76. ~ |
  77. ~ |
  78. ~ |
  79. -- INSERT (paste) -- |
  80. ]])
  81. feed(table.concat(t, '<Enter>'))
  82. screen:expect([[
  83. item 19988 |
  84. item 19989 |
  85. item 19990 |
  86. item 19991 |
  87. item 19992 |
  88. item 19993 |
  89. item 19994 |
  90. item 19995 |
  91. item 19996 |
  92. item 19997 |
  93. item 19998 |
  94. item 19999 |
  95. item 20000^ |
  96. -- INSERT (paste) -- |
  97. ]])
  98. feed('<Paste>')
  99. screen:expect([[
  100. item 19988 |
  101. item 19989 |
  102. item 19990 |
  103. item 19991 |
  104. item 19992 |
  105. item 19993 |
  106. item 19994 |
  107. item 19995 |
  108. item 19996 |
  109. item 19997 |
  110. item 19998 |
  111. item 19999 |
  112. item 20000^ |
  113. -- INSERT -- 20000,11 Bot |
  114. ]])
  115. end)
  116. end)
  117. describe('input utf sequences that contain CSI/K_SPECIAL', function()
  118. before_each(clear)
  119. it('ok', function()
  120. feed('i…<esc>')
  121. expect('…')
  122. end)
  123. end)
  124. describe('input non-printable chars', function()
  125. after_each(function()
  126. os.remove('Xtest-overwrite')
  127. end)
  128. it("doesn't crash when echoing them back", function()
  129. write_file("Xtest-overwrite", [[foobar]])
  130. clear()
  131. local screen = Screen.new(60,8)
  132. screen:set_default_attr_ids({
  133. [1] = {bold = true, foreground = Screen.colors.Blue1},
  134. [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
  135. [3] = {bold = true, foreground = Screen.colors.SeaGreen4}
  136. })
  137. screen:attach()
  138. command("set display-=msgsep shortmess-=F")
  139. feed_command("e Xtest-overwrite")
  140. screen:expect([[
  141. ^foobar |
  142. {1:~ }|
  143. {1:~ }|
  144. {1:~ }|
  145. {1:~ }|
  146. {1:~ }|
  147. {1:~ }|
  148. "Xtest-overwrite" [noeol] 1L, 6C |
  149. ]])
  150. -- The timestamp is in second resolution, wait two seconds to be sure.
  151. screen:sleep(2000)
  152. write_file("Xtest-overwrite", [[smurf]])
  153. feed_command("w")
  154. screen:expect([[
  155. {1:~ }|
  156. {1:~ }|
  157. {1:~ }|
  158. {1:~ }|
  159. {1:~ }|
  160. "Xtest-overwrite" |
  161. {2:WARNING: The file has been changed since reading it!!!} |
  162. {3:Do you really want to write to it (y/n)?}^ |
  163. ]])
  164. feed("u")
  165. screen:expect([[
  166. {1:~ }|
  167. {1:~ }|
  168. {1:~ }|
  169. {1:~ }|
  170. "Xtest-overwrite" |
  171. {2:WARNING: The file has been changed since reading it!!!} |
  172. {3:Do you really want to write to it (y/n)?}u |
  173. {3:Do you really want to write to it (y/n)?}^ |
  174. ]])
  175. feed("\005")
  176. screen:expect([[
  177. {1:~ }|
  178. {1:~ }|
  179. {1:~ }|
  180. "Xtest-overwrite" |
  181. {2:WARNING: The file has been changed since reading it!!!} |
  182. {3:Do you really want to write to it (y/n)?}u |
  183. {3:Do you really want to write to it (y/n)?} |
  184. {3:Do you really want to write to it (y/n)?}^ |
  185. ]])
  186. feed("n")
  187. screen:expect([[
  188. {1:~ }|
  189. {1:~ }|
  190. "Xtest-overwrite" |
  191. {2:WARNING: The file has been changed since reading it!!!} |
  192. {3:Do you really want to write to it (y/n)?}u |
  193. {3:Do you really want to write to it (y/n)?} |
  194. {3:Do you really want to write to it (y/n)?}n |
  195. {3:Press ENTER or type command to continue}^ |
  196. ]])
  197. feed("<cr>")
  198. screen:expect([[
  199. ^foobar |
  200. {1:~ }|
  201. {1:~ }|
  202. {1:~ }|
  203. {1:~ }|
  204. {1:~ }|
  205. {1:~ }|
  206. |
  207. ]])
  208. end)
  209. end)