robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
4.3 KiB156 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local exec_lua = n.exec_lua
6local eq = t.eq
7local eval = n.eval
8local clear = n.clear
9
10describe('vim.inspect_pos', function()
11  before_each(function()
12    clear()
13  end)
14
15  it('it returns items', function()
16    local buf, ns1, ns2 = exec_lua(function()
17      local buf = vim.api.nvim_create_buf(true, false)
18      _G.buf1 = vim.api.nvim_create_buf(true, false)
19      local ns1 = vim.api.nvim_create_namespace('ns1')
20      local ns2 = vim.api.nvim_create_namespace('')
21      vim.api.nvim_set_current_buf(buf)
22      vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' })
23      vim.api.nvim_buf_set_lines(_G.buf1, 0, -1, false, { '--commentline' })
24      vim.bo[buf].filetype = 'lua'
25      vim.bo[_G.buf1].filetype = 'lua'
26      vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = 'Normal' })
27      vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = 'Normal', end_col = 10 })
28      vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = 'Normal', end_col = 11 })
29      vim.cmd('syntax on')
30      return buf, ns1, ns2
31    end)
32
33    eq('', eval('v:errmsg'))
34    -- Only visible highlights with `filter.extmarks == true`
35    eq({
36      buffer = buf,
37      col = 10,
38      row = 0,
39      extmarks = {
40        {
41          col = 10,
42          end_col = 11,
43          end_row = 0,
44          id = 1,
45          ns = '',
46          ns_id = ns2,
47          opts = {
48            end_row = 0,
49            end_col = 11,
50            hl_eol = false,
51            hl_group = 'Normal',
52            hl_group_link = 'Normal',
53            ns_id = ns2,
54            priority = 4096,
55            right_gravity = true,
56            end_right_gravity = false,
57          },
58          row = 0,
59        },
60      },
61      treesitter = {},
62      semantic_tokens = {},
63      syntax = { { hl_group = 'luaNumber', hl_group_link = 'Constant' } },
64    }, exec_lua('return vim.inspect_pos(0, 0, 10)'))
65    -- All extmarks with `filters.extmarks == 'all'`
66    eq({
67      buffer = buf,
68      col = 10,
69      row = 0,
70      extmarks = {
71        {
72          col = 10,
73          end_col = 10,
74          end_row = 0,
75          id = 1,
76          ns = 'ns1',
77          ns_id = ns1,
78          opts = {
79            hl_eol = false,
80            hl_group = 'Normal',
81            hl_group_link = 'Normal',
82            ns_id = ns1,
83            priority = 4096,
84            right_gravity = true,
85          },
86          row = 0,
87        },
88        {
89          col = 10,
90          end_col = 11,
91          end_row = 0,
92          id = 1,
93          ns = '',
94          ns_id = ns2,
95          opts = {
96            end_row = 0,
97            end_col = 11,
98            hl_eol = false,
99            hl_group = 'Normal',
100            hl_group_link = 'Normal',
101            ns_id = ns2,
102            priority = 4096,
103            right_gravity = true,
104            end_right_gravity = false,
105          },
106          row = 0,
107        },
108        {
109          col = 10,
110          end_col = 10,
111          end_row = 0,
112          id = 2,
113          ns = 'ns1',
114          ns_id = ns1,
115          opts = {
116            end_row = 0,
117            end_col = 10,
118            hl_eol = false,
119            hl_group = 'Normal',
120            hl_group_link = 'Normal',
121            ns_id = ns1,
122            priority = 4096,
123            right_gravity = true,
124            end_right_gravity = false,
125          },
126          row = 0,
127        },
128      },
129      treesitter = {},
130      semantic_tokens = {},
131      syntax = { { hl_group = 'luaNumber', hl_group_link = 'Constant' } },
132    }, exec_lua('return vim.inspect_pos(0, 0, 10, { extmarks = "all" })'))
133    -- Syntax from other buffer.
134    eq({
135      { hl_group = 'luaComment', hl_group_link = 'Comment' },
136    }, exec_lua('return vim.inspect_pos(_G.buf1, 0, 10).syntax'))
137  end)
138end)
139
140describe('vim.show_pos', function()
141  before_each(function()
142    clear()
143  end)
144
145  it('it does not error', function()
146    exec_lua(function()
147      local buf = vim.api.nvim_create_buf(true, false)
148      vim.api.nvim_set_current_buf(buf)
149      vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' })
150      vim.bo[buf].filetype = 'lua'
151      vim.cmd('syntax on')
152      return { buf, vim.show_pos(0, 0, 10) }
153    end)
154    eq('', eval('v:errmsg'))
155  end)
156end)