robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.1 KiB34 linesraw
1local t = require('test.testutil')
2
3local describe, it = t.describe, t.it
4describe('vim.trim()', function()
5  local strings = {
6    ['10000 whitespace characters'] = string.rep(' ', 10000),
7    ['10000 whitespace characters and one non-whitespace at the end'] = string.rep(' ', 10000)
8      .. '0',
9    ['10000 whitespace characters and one non-whitespace at the start'] = '0'
10      .. string.rep(' ', 10000),
11    ['10000 non-whitespace characters'] = string.rep('0', 10000),
12    ['10000 whitespace and one non-whitespace in the middle'] = string.rep(' ', 5000)
13      .. 'a'
14      .. string.rep(' ', 5000),
15    ['10000 whitespace characters surrounded by non-whitespace'] = '0'
16      .. string.rep(' ', 10000)
17      .. '0',
18    ['10000 non-whitespace characters surrounded by whitespace'] = ' '
19      .. string.rep('0', 10000)
20      .. ' ',
21  }
22
23  --- @type string[]
24  local string_names = vim.tbl_keys(strings)
25  table.sort(string_names)
26
27  for _, name in ipairs(string_names) do
28    it(name, function()
29      t.bench(function()
30        vim.trim(strings[name])
31      end, { n = 100, label = name })
32    end)
33  end
34end)