autocmd_oldtest_spec.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear = n.clear
  5. local eq = t.eq
  6. local api = n.api
  7. local fn = n.fn
  8. local exec = n.exec
  9. local feed = n.feed
  10. local assert_log = t.assert_log
  11. local check_close = n.check_close
  12. local is_os = t.is_os
  13. local testlog = 'Xtest_autocmd_oldtest_log'
  14. describe('oldtests', function()
  15. before_each(clear)
  16. after_each(function()
  17. check_close()
  18. os.remove(testlog)
  19. end)
  20. local exec_lines = function(str)
  21. return fn.split(fn.execute(str), '\n')
  22. end
  23. local add_an_autocmd = function()
  24. exec [[
  25. augroup vimBarTest
  26. au BufReadCmd * echo 'hello'
  27. augroup END
  28. ]]
  29. eq(3, #exec_lines('au vimBarTest'))
  30. eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' }))
  31. end
  32. it('should recognize a bar before the {event}', function()
  33. -- Good spacing
  34. add_an_autocmd()
  35. exec [[ augroup vimBarTest | au! | augroup END ]]
  36. eq(1, #exec_lines('au vimBarTest'))
  37. eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' }))
  38. -- Sad spacing
  39. add_an_autocmd()
  40. exec [[ augroup vimBarTest| au!| augroup END ]]
  41. eq(1, #exec_lines('au vimBarTest'))
  42. -- test that a bar is recognized after the {event}
  43. add_an_autocmd()
  44. exec [[ augroup vimBarTest| au!BufReadCmd| augroup END ]]
  45. eq(1, #exec_lines('au vimBarTest'))
  46. add_an_autocmd()
  47. exec [[ au! vimBarTest|echo 'hello' ]]
  48. eq(1, #exec_lines('au vimBarTest'))
  49. end)
  50. it('should fire on unload buf', function()
  51. clear({ env = { NVIM_LOG_FILE = testlog } })
  52. fn.writefile({ 'Test file Xxx1' }, 'Xxx1')
  53. fn.writefile({ 'Test file Xxx2' }, 'Xxx2')
  54. local fname = 'Xtest_functional_autocmd_unload'
  55. local content = [[
  56. func UnloadAllBufs()
  57. let i = 1
  58. while i <= bufnr('$')
  59. if i != bufnr('%') && bufloaded(i)
  60. exe i . 'bunload'
  61. endif
  62. let i += 1
  63. endwhile
  64. endfunc
  65. au BufUnload * call UnloadAllBufs()
  66. au VimLeave * call writefile(['Test Finished'], 'Xout')
  67. set nohidden
  68. edit Xxx1
  69. split Xxx2
  70. q
  71. ]]
  72. fn.writefile(fn.split(content, '\n'), fname)
  73. fn.delete('Xout')
  74. fn.system(string.format('%s --clean -N -S %s', api.nvim_get_vvar('progpath'), fname))
  75. eq(1, fn.filereadable('Xout'))
  76. fn.delete('Xxx1')
  77. fn.delete('Xxx2')
  78. fn.delete(fname)
  79. fn.delete('Xout')
  80. if is_os('win') then
  81. assert_log('stream write failed. RPC canceled; closing channel', testlog)
  82. end
  83. end)
  84. -- oldtest: Test_delete_ml_get_errors()
  85. it('no ml_get error with TextChanged autocommand and delete', function()
  86. local screen = Screen.new(75, 10)
  87. screen:add_extra_attr_ids {
  88. [100] = { background = Screen.colors.Cyan1 },
  89. }
  90. exec([[
  91. set noshowcmd noruler scrolloff=0
  92. source test/old/testdir/samples/matchparen.vim
  93. edit test/old/testdir/samples/box.txt
  94. ]])
  95. feed('249GV<C-End>d')
  96. screen:expect {
  97. grid = [[
  98. const auto themeEmoji = _forPeer->themeEmoji(); |
  99. if (themeEmoji.isEmpty()) { |
  100. return nonCustom; |
  101. } |
  102. const auto &themes = _forPeer->owner().cloudThemes(); |
  103. const auto theme = themes.themeForEmoji(themeEmoji); |
  104. if (!theme) {100:{} |
  105. return nonCustom; |
  106. {100:^}} |
  107. 353 fewer lines |
  108. ]],
  109. }
  110. feed('<PageUp>')
  111. screen:expect {
  112. grid = [[
  113. |
  114. auto BackgroundBox::Inner::resolveResetCustomPaper() const |
  115. -> std::optional<Data::WallPaper> { |
  116. if (!_forPeer) { |
  117. return {}; |
  118. } |
  119. const auto nonCustom = Window::Theme::Background()->paper(); |
  120. const auto themeEmoji = _forPeer->themeEmoji(); |
  121. ^if (themeEmoji.isEmpty()) { |
  122. 353 fewer lines |
  123. ]],
  124. }
  125. end)
  126. end)