inspector_spec.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local exec_lua = helpers.exec_lua
  3. local eq = helpers.eq
  4. local eval = helpers.eval
  5. local clear = helpers.clear
  6. describe('vim.inspect_pos', function()
  7. before_each(function()
  8. clear()
  9. end)
  10. it('it returns items', function()
  11. local ret = exec_lua([[
  12. local buf = vim.api.nvim_create_buf(true, false)
  13. local buf1 = vim.api.nvim_create_buf(true, false)
  14. local ns1 = vim.api.nvim_create_namespace("ns1")
  15. local ns2 = vim.api.nvim_create_namespace("")
  16. vim.api.nvim_set_current_buf(buf)
  17. vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
  18. vim.api.nvim_buf_set_lines(buf1, 0, -1, false, {"--commentline"})
  19. vim.api.nvim_buf_set_option(buf, "filetype", "lua")
  20. vim.api.nvim_buf_set_option(buf1, "filetype", "lua")
  21. vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" })
  22. vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" })
  23. vim.cmd("syntax on")
  24. return {buf, vim.inspect_pos(0, 0, 10), vim.inspect_pos(buf1, 0, 10).syntax }
  25. ]])
  26. local buf, items, other_buf_syntax = unpack(ret)
  27. eq('', eval('v:errmsg'))
  28. eq({
  29. buffer = buf,
  30. col = 10,
  31. row = 0,
  32. extmarks = {
  33. {
  34. col = 10,
  35. end_col = 11,
  36. end_row = 0,
  37. id = 1,
  38. ns = 'ns1',
  39. ns_id = 1,
  40. opts = {
  41. hl_eol = false,
  42. hl_group = 'Normal',
  43. hl_group_link = 'Normal',
  44. ns_id = 1,
  45. priority = 4096,
  46. right_gravity = true
  47. },
  48. row = 0
  49. },
  50. {
  51. col = 10,
  52. end_col = 11,
  53. end_row = 0,
  54. id = 1,
  55. ns = '',
  56. ns_id = 2,
  57. opts = {
  58. hl_eol = false,
  59. hl_group = 'Normal',
  60. hl_group_link = 'Normal',
  61. ns_id = 2,
  62. priority = 4096,
  63. right_gravity = true
  64. },
  65. row = 0
  66. }
  67. },
  68. treesitter = {},
  69. semantic_tokens = {},
  70. syntax = {
  71. {
  72. hl_group = 'luaNumber',
  73. hl_group_link = 'Constant',
  74. },
  75. },
  76. }, items)
  77. eq({
  78. {
  79. hl_group = 'luaComment',
  80. hl_group_link = 'Comment',
  81. },
  82. }, other_buf_syntax)
  83. end)
  84. end)
  85. describe('vim.show_pos', function()
  86. before_each(function()
  87. clear()
  88. end)
  89. it('it does not error', function()
  90. exec_lua([[
  91. local buf = vim.api.nvim_create_buf(true, false)
  92. vim.api.nvim_set_current_buf(buf)
  93. vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
  94. vim.api.nvim_buf_set_option(buf, "filetype", "lua")
  95. vim.cmd("syntax on")
  96. return {buf, vim.show_pos(0, 0, 10)}
  97. ]])
  98. eq('', eval('v:errmsg'))
  99. end)
  100. end)