diff options
author | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2019-10-21 23:46:28 +0900 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-10-26 00:27:01 -0700 |
commit | 996a057fb9b4b7d791adad19f07b2f9c53a88ab5 (patch) | |
tree | fca179ca156ec70140f80e7764da1749bbda8244 /runtime/lua/vim/shared.lua | |
parent | 91b831da8b00319afba6a90b439d70960f90c3f7 (diff) | |
download | rneovim-996a057fb9b4b7d791adad19f07b2f9c53a88ab5.tar.gz rneovim-996a057fb9b4b7d791adad19f07b2f9c53a88ab5.tar.bz2 rneovim-996a057fb9b4b7d791adad19f07b2f9c53a88ab5.zip |
lua/stdlib: adjust some validation messages #11271
close #11271
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 |