screenchar_spec.lua 2.0 KB

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