diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-10-26 02:30:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-26 02:30:40 -0700 |
commit | 19ba36d0e1bb4ef28f8aa92c7386345fbcf78cf2 (patch) | |
tree | f8e95ef890acd6ee9fecb9d56a1093dfc4d1df8a /runtime/lua/vim/shared.lua | |
parent | 91b831da8b00319afba6a90b439d70960f90c3f7 (diff) | |
parent | 316c29bbf36d3d36c459b7c955d921b29ca659d0 (diff) | |
download | rneovim-19ba36d0e1bb4ef28f8aa92c7386345fbcf78cf2.tar.gz rneovim-19ba36d0e1bb4ef28f8aa92c7386345fbcf78cf2.tar.bz2 rneovim-19ba36d0e1bb4ef28f8aa92c7386345fbcf78cf2.zip |
Merge #11271 from h-michael/add-more-info
lua/vim.shared: improve some validation messages
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index cd6f8a04d8..220b6c6c7c 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -44,9 +44,9 @@ end --@param plain If `true` use `sep` literally (passed to String.find) --@returns Iterator over the split components local function gsplit(s, sep, plain) - assert(type(s) == "string") - assert(type(sep) == "string") - assert(type(plain) == "boolean" or type(plain) == "nil") + assert(type(s) == "string", string.format("Expected string, got %s", type(s))) + assert(type(sep) == "string", string.format("Expected string, got %s", type(sep))) + assert(type(plain) == "boolean" or type(plain) == "nil", string.format("Expected boolean or nil, got %s", type(plain))) local start = 1 local done = false @@ -103,9 +103,8 @@ end --@param value Value to compare --@returns true if `t` contains `value` local function tbl_contains(t, value) - if type(t) ~= 'table' then - error('t must be a table') - end + assert(type(t) == 'table', string.format("Expected table, got %s", type(t))) + for _,v in ipairs(t) do if v == value then return true @@ -174,7 +173,7 @@ end --@param s String to trim --@returns String with whitespace removed from its beginning and end local function trim(s) - assert(type(s) == 'string', 'Only strings can be trimmed') + assert(type(s) == 'string', string.format("Expected string, got %s", type(s))) return s:match('^%s*(.*%S)') or '' end @@ -184,7 +183,7 @@ end --@param s String to escape --@returns %-escaped pattern string local function pesc(s) - assert(type(s) == 'string') + assert(type(s) == 'string', string.format("Expected string, got %s", type(s))) return s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1') end |