mirror of
https://github.com/neovim/neovim.git
synced 2025-11-14 14:29:02 +00:00
Merge #9463 'Lua stdlib'
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
|
||||
local funcs = helpers.funcs
|
||||
local meths = helpers.meths
|
||||
local clear = helpers.clear
|
||||
local eq = helpers.eq
|
||||
|
||||
@@ -106,3 +107,91 @@ describe('vim.stricmp', function()
|
||||
eq(1, funcs.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("vim.split", function()
|
||||
it("works", function()
|
||||
local split = function(str, sep)
|
||||
return meths.execute_lua('return vim.split(...)', {str, sep})
|
||||
end
|
||||
|
||||
local tests = {
|
||||
{ "a,b", ",", false, { 'a', 'b' } },
|
||||
{ ":aa::bb:", ":", false, { '', 'aa', '', 'bb', '' } },
|
||||
{ "::ee::ff:", ":", false, { '', '', 'ee', '', 'ff', '' } },
|
||||
{ "ab", ".", false, { '', '', '' } },
|
||||
{ "a1b2c", "[0-9]", false, { 'a', 'b', 'c' } },
|
||||
{ "xy", "", false, { 'x', 'y' } },
|
||||
{ "here be dragons", " ", false, { "here", "be", "dragons"} },
|
||||
{ "axaby", "ab?", false, { '', 'x', 'y' } },
|
||||
{ "f v2v v3v w2w ", "([vw])2%1", false, { 'f ', ' v3v ', ' ' } },
|
||||
{ "x*yz*oo*l", "*", true, { 'x', 'yz', 'oo', 'l' } },
|
||||
}
|
||||
|
||||
for _, t in ipairs(tests) do
|
||||
eq(t[4], split(t[1], t[2], t[3]))
|
||||
end
|
||||
|
||||
local loops = {
|
||||
{ "abc", ".-" },
|
||||
}
|
||||
|
||||
for _, t in ipairs(loops) do
|
||||
local status, err = pcall(split, t[1], t[2])
|
||||
eq(false, status)
|
||||
assert(string.match(err, "Infinite loop detected"))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("vim.trim", function()
|
||||
it('works', function()
|
||||
local trim = function(s)
|
||||
return meths.execute_lua('return vim.trim(...)', { s })
|
||||
end
|
||||
|
||||
local trims = {
|
||||
{ " a", "a" },
|
||||
{ " b ", "b" },
|
||||
{ "\tc" , "c" },
|
||||
{ "r\n", "r" },
|
||||
}
|
||||
|
||||
for _, t in ipairs(trims) do
|
||||
assert(t[2], trim(t[1]))
|
||||
end
|
||||
|
||||
local status, err = pcall(trim, 2)
|
||||
eq(false, status)
|
||||
assert(string.match(err, "Only strings can be trimmed"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("vim.inspect", function()
|
||||
it('works', function()
|
||||
-- just make sure it basically works, it has its own test suite
|
||||
local inspect = function(t, opts)
|
||||
return meths.execute_lua('return vim.inspect(...)', { t, opts })
|
||||
end
|
||||
|
||||
eq('2', inspect(2))
|
||||
eq('{+a = {+b = 1+}+}',
|
||||
inspect({ a = { b = 1 } }, { newline = '+', indent = '' }))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("vim.deepcopy", function()
|
||||
it("works", function()
|
||||
local is_dc = meths.execute_lua([[
|
||||
local a = { x = { 1, 2 }, y = 5}
|
||||
local b = vim.deepcopy(a)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(b) do count = count + 1 end
|
||||
|
||||
return b.x[1] == 1 and b.x[2] == 2 and b.y == 5 and count == 2
|
||||
and tostring(a) ~= tostring(b)
|
||||
]], {})
|
||||
|
||||
assert(is_dc)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user