mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix: vim.validate() order is not deterministic #28377
Problem: The order of the validation performed by vim.validate() is unpredictable. - harder to write reliable tests. - confusing UX because validation result might return different errors randomly. Solution: Iterate the input using `vim.spairs()`. Future: Ideally, the caller could provide an "ordered dict".
This commit is contained in:
parent
5cfdaaaeac
commit
fe4583127f
@ -2376,7 +2376,8 @@ vim.trim({s}) *vim.trim()*
|
|||||||
• https://www.lua.org/pil/20.2.html
|
• https://www.lua.org/pil/20.2.html
|
||||||
|
|
||||||
vim.validate({opt}) *vim.validate()*
|
vim.validate({opt}) *vim.validate()*
|
||||||
Validates a parameter specification (types and values).
|
Validates a parameter specification (types and values). Specs are
|
||||||
|
evaluated in alphanumeric order, until the first failure.
|
||||||
|
|
||||||
Usage example: >lua
|
Usage example: >lua
|
||||||
function user.new(name, age, hobbies)
|
function user.new(name, age, hobbies)
|
||||||
|
@ -578,7 +578,7 @@ end
|
|||||||
---@return fun(table: table<K, V>, index?: K):K, V # |for-in| iterator over sorted keys and their values
|
---@return fun(table: table<K, V>, index?: K):K, V # |for-in| iterator over sorted keys and their values
|
||||||
---@return T
|
---@return T
|
||||||
function vim.spairs(t)
|
function vim.spairs(t)
|
||||||
vim.validate({ t = { t, 't' } })
|
assert(type(t) == 'table', ('expected table, got %s'):format(type(t)))
|
||||||
--- @cast t table<any,any>
|
--- @cast t table<any,any>
|
||||||
|
|
||||||
-- collect the keys
|
-- collect the keys
|
||||||
@ -795,7 +795,7 @@ do
|
|||||||
return false, string.format('opt: expected table, got %s', type(opt))
|
return false, string.format('opt: expected table, got %s', type(opt))
|
||||||
end
|
end
|
||||||
|
|
||||||
for param_name, spec in pairs(opt) do
|
for param_name, spec in vim.spairs(opt) do
|
||||||
if type(spec) ~= 'table' then
|
if type(spec) ~= 'table' then
|
||||||
return false, string.format('opt[%s]: expected table, got %s', param_name, type(spec))
|
return false, string.format('opt[%s]: expected table, got %s', param_name, type(spec))
|
||||||
end
|
end
|
||||||
@ -851,7 +851,8 @@ do
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Validates a parameter specification (types and values).
|
--- Validates a parameter specification (types and values). Specs are evaluated in alphanumeric
|
||||||
|
--- order, until the first failure.
|
||||||
---
|
---
|
||||||
--- Usage example:
|
--- Usage example:
|
||||||
---
|
---
|
||||||
|
Loading…
Reference in New Issue
Block a user