robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.4 KiB123 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
6local clear = n.clear
7local exec_lua = n.exec_lua
8
9describe('extmark perf', function()
10  before_each(function()
11    clear()
12
13    exec_lua([[
14      out = {}
15      function start()
16        ts = vim.uv.hrtime()
17      end
18      function stop(name)
19        out[#out+1] = ('%14.6f ms - %s'):format((vim.uv.hrtime() - ts) / 1000000, name)
20      end
21    ]])
22  end)
23
24  after_each(function()
25    for _, line in ipairs(exec_lua([[return out]])) do
26      print(line)
27    end
28  end)
29
30  it('repeatedly calling nvim_buf_clear_namespace #28615', function()
31    exec_lua([[
32      vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'foo', 'bar' })
33      local ns0 = vim.api.nvim_create_namespace('ns0')
34      local ns1 = vim.api.nvim_create_namespace('ns1')
35
36      for _ = 1, 10000 do
37        vim.api.nvim_buf_set_extmark(0, ns0, 0, 0, {})
38      end
39      vim.api.nvim_buf_set_extmark(0, ns1, 1, 0, {})
40
41      start()
42      for _ = 1, 10000 do
43        vim.api.nvim_buf_clear_namespace(0, ns1, 0, -1)
44      end
45      stop('nvim_buf_clear_namespace')
46    ]])
47  end)
48
49  it('many non-wrapped virtual lines', function()
50    local screen = Screen.new(40, 999)
51    exec_lua([[
52      vim.cmd('1new')
53      vim.api.nvim_buf_set_lines(0, 0, -1, true, { 'line1', 'line2', 'line3' })
54      local ns = vim.api.nvim_create_namespace('virt_lines')
55      local virt_lines = {}
56      for i = 1, 2000 do
57        virt_lines[i] = { { 'VIRT_LINE', 'ErrorMsg' } }
58      end
59      vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines = virt_lines })
60    ]])
61
62    exec_lua([[
63      vim.cmd('resize 995')
64
65      start()
66      vim.cmd('redraw')
67      stop('redraw with virt lines at the bottom')
68    ]])
69    screen:expect([[
70      ^line1                                   |
71      {9:VIRT_LINE}                               |*994
72      {3:[No Name] [+]                           }|
73                                              |
74      {2:[No Name]                               }|
75                                              |
76    ]])
77
78    n.command('resize 1')
79    screen:expect([[
80      ^line1                                   |
81      {3:[No Name] [+]                           }|
82                                              |
83      {1:~                                       }|*994
84      {2:[No Name]                               }|
85                                              |
86    ]])
87
88    exec_lua([[
89      vim.cmd('resize 995')
90
91      start()
92      vim.cmd('normal! j')
93      stop('moving cursor down to line 2')
94
95      start()
96      vim.cmd('normal! j')
97      stop('moving cursor down to line 3')
98
99      start()
100      vim.cmd('redraw')
101      stop('redraw with virt lines at the top')
102    ]])
103    screen:expect([[
104      {9:VIRT_LINE}                               |*993
105      line2                                   |
106      ^line3                                   |
107      {3:[No Name] [+]                           }|
108                                              |
109      {2:[No Name]                               }|
110                                              |
111    ]])
112
113    exec_lua([[
114      start()
115      vim.cmd('normal! k')
116      stop('moving cursor up to line 2')
117
118      start()
119      vim.cmd('normal! k')
120      stop('moving cursor up to line 1')
121    ]])
122  end)
123end)