api_spec.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local tt = require('test.functional.testterm')
  4. local ok = t.ok
  5. if t.skip(t.is_os('win')) then
  6. return
  7. end
  8. describe('api', function()
  9. local screen
  10. local socket_name = './Xtest_functional_api.sock'
  11. before_each(function()
  12. n.clear()
  13. os.remove(socket_name)
  14. screen = tt.setup_child_nvim({
  15. '-u',
  16. 'NONE',
  17. '-i',
  18. 'NONE',
  19. '--cmd',
  20. 'colorscheme vim',
  21. '--cmd',
  22. n.nvim_set .. ' notermguicolors',
  23. })
  24. end)
  25. after_each(function()
  26. os.remove(socket_name)
  27. end)
  28. it('qa! RPC request during insert-mode', function()
  29. screen:expect {
  30. grid = [[
  31. {1: } |
  32. {4:~ }|*4
  33. |
  34. {3:-- TERMINAL --} |
  35. ]],
  36. }
  37. -- Start the socket from the child nvim.
  38. tt.feed_data(":echo serverstart('" .. socket_name .. "')\n")
  39. -- Wait for socket creation.
  40. screen:expect([[
  41. {1: } |
  42. {4:~ }|*4
  43. ]] .. socket_name .. [[ |
  44. {3:-- TERMINAL --} |
  45. ]])
  46. local socket_session1 = n.connect(socket_name)
  47. local socket_session2 = n.connect(socket_name)
  48. tt.feed_data('i[tui] insert-mode')
  49. -- Wait for stdin to be processed.
  50. screen:expect([[
  51. [tui] insert-mode{1: } |
  52. {4:~ }|*4
  53. {3:-- INSERT --} |
  54. {3:-- TERMINAL --} |
  55. ]])
  56. ok((socket_session1:request('nvim_ui_attach', 42, 6, { rgb = true })))
  57. ok((socket_session2:request('nvim_ui_attach', 25, 30, { rgb = true })))
  58. socket_session1:notify('nvim_input', '\n[socket 1] this is more than 25 columns')
  59. socket_session2:notify('nvim_input', '\n[socket 2] input')
  60. screen:expect([[
  61. [tui] insert-mode |
  62. [socket 1] this is more t |
  63. han 25 columns |
  64. [socket 2] input{1: } |
  65. {4:~ } |
  66. {3:-- INSERT --} |
  67. {3:-- TERMINAL --} |
  68. ]])
  69. socket_session1:request('nvim_command', 'qa!')
  70. end)
  71. end)