focus_spec.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local tt = require('test.functional.testterm')
  4. local clear = n.clear
  5. local feed_command = n.feed_command
  6. local feed_data = tt.feed_data
  7. if t.skip(t.is_os('win')) then
  8. return
  9. end
  10. describe('autoread TUI FocusGained/FocusLost', function()
  11. local f1 = 'xtest-foo'
  12. local screen
  13. before_each(function()
  14. clear()
  15. screen = tt.setup_child_nvim({
  16. '-u',
  17. 'NONE',
  18. '-i',
  19. 'NONE',
  20. '--cmd',
  21. 'colorscheme vim',
  22. '--cmd',
  23. 'set noswapfile noshowcmd noruler notermguicolors',
  24. })
  25. end)
  26. teardown(function()
  27. os.remove(f1)
  28. end)
  29. it('external file change', function()
  30. local path = f1
  31. local expected_addition = [[
  32. line 1
  33. line 2
  34. line 3
  35. line 4
  36. ]]
  37. t.write_file(path, '')
  38. local atime = os.time() - 10
  39. vim.uv.fs_utime(path, atime, atime)
  40. screen:expect {
  41. grid = [[
  42. {1: } |
  43. {4:~ }|*3
  44. {5:[No Name] }|
  45. |
  46. {3:-- TERMINAL --} |
  47. ]],
  48. }
  49. feed_command('edit ' .. path)
  50. screen:expect {
  51. grid = [[
  52. {1: } |
  53. {4:~ }|*3
  54. {5:xtest-foo }|
  55. :edit xtest-foo |
  56. {3:-- TERMINAL --} |
  57. ]],
  58. }
  59. feed_data('\027[O')
  60. feed_data('\027[O')
  61. screen:expect {
  62. grid = [[
  63. {1: } |
  64. {4:~ }|*3
  65. {5:xtest-foo }|
  66. :edit xtest-foo |
  67. {3:-- TERMINAL --} |
  68. ]],
  69. unchanged = true,
  70. }
  71. t.write_file(path, expected_addition)
  72. feed_data('\027[I')
  73. screen:expect {
  74. grid = [[
  75. {1:l}ine 1 |
  76. line 2 |
  77. line 3 |
  78. line 4 |
  79. {5:xtest-foo }|
  80. :edit xtest-foo |
  81. {3:-- TERMINAL --} |
  82. ]],
  83. }
  84. end)
  85. end)