neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

inspector_spec.lua (4305B)


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