screenchar_spec.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, eq, neq = n.clear, t.eq, t.neq
  5. local command, api, fn = n.command, n.api, n.fn
  6. local tbl_deep_extend = vim.tbl_deep_extend
  7. -- Set up two overlapping floating windows
  8. local setup_floating_windows = function()
  9. local base_opts = {
  10. relative = 'editor',
  11. height = 1,
  12. width = 2,
  13. anchor = 'NW',
  14. style = 'minimal',
  15. border = 'none',
  16. }
  17. local bufnr_1 = api.nvim_create_buf(false, true)
  18. api.nvim_buf_set_lines(bufnr_1, 0, -1, true, { 'aa' })
  19. local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts)
  20. api.nvim_open_win(bufnr_1, false, opts_1)
  21. local bufnr_2 = api.nvim_create_buf(false, true)
  22. api.nvim_buf_set_lines(bufnr_2, 0, -1, true, { 'bb' })
  23. local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts)
  24. api.nvim_open_win(bufnr_2, false, opts_2)
  25. command('redraw')
  26. end
  27. describe('screenchar() and family respect floating windows', function()
  28. local function with_ext_multigrid(multigrid)
  29. before_each(function()
  30. clear()
  31. Screen.new(40, 7, { ext_multigrid = multigrid })
  32. -- These commands result into visible text `aabc`.
  33. -- `aab` - from floating windows, `c` - from text in regular window.
  34. api.nvim_buf_set_lines(0, 0, -1, true, { 'cccc' })
  35. setup_floating_windows()
  36. end)
  37. it('screenattr()', function()
  38. local attr_1 = fn.screenattr(1, 1)
  39. local attr_2 = fn.screenattr(1, 2)
  40. local attr_3 = fn.screenattr(1, 3)
  41. local attr_4 = fn.screenattr(1, 4)
  42. eq(attr_1, attr_2)
  43. eq(attr_1, attr_3)
  44. neq(attr_1, attr_4)
  45. end)
  46. it('screenchar()', function()
  47. eq(97, fn.screenchar(1, 1))
  48. eq(97, fn.screenchar(1, 2))
  49. eq(98, fn.screenchar(1, 3))
  50. eq(99, fn.screenchar(1, 4))
  51. end)
  52. it('screenchars()', function()
  53. eq({ 97 }, fn.screenchars(1, 1))
  54. eq({ 97 }, fn.screenchars(1, 2))
  55. eq({ 98 }, fn.screenchars(1, 3))
  56. eq({ 99 }, fn.screenchars(1, 4))
  57. end)
  58. it('screenstring()', function()
  59. eq('a', fn.screenstring(1, 1))
  60. eq('a', fn.screenstring(1, 2))
  61. eq('b', fn.screenstring(1, 3))
  62. eq('c', fn.screenstring(1, 4))
  63. end)
  64. end
  65. describe('with ext_multigrid', function()
  66. with_ext_multigrid(true)
  67. end)
  68. describe('without ext_multigrid', function()
  69. with_ext_multigrid(false)
  70. end)
  71. end)