From af946046b922dc5d5285a70a23d11916d8389a5d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 3 Sep 2019 22:51:45 +0200 Subject: test: Rename meth_pcall to pcall_err - Rename `meth_pcall`. - Make `pcall_err` raise an error if the function does not fail. - Add `vim.pesc()` to treat a string as literal where a Lua pattern is expected. --- test/functional/lua/utility_functions_spec.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test/functional/lua/utility_functions_spec.lua') diff --git a/test/functional/lua/utility_functions_spec.lua b/test/functional/lua/utility_functions_spec.lua index ff15ebf8b3..ea2b1fc8a9 100644 --- a/test/functional/lua/utility_functions_spec.lua +++ b/test/functional/lua/utility_functions_spec.lua @@ -7,12 +7,12 @@ local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local meth_pcall = helpers.meth_pcall +local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua before_each(clear) -describe('lua function', function() +describe('lua stdlib', function() -- İ: `tolower("İ")` is `i` which has length 1 while `İ` itself has -- length 2 (in bytes). -- Ⱥ: `tolower("Ⱥ")` is `ⱥ` which has length 2 while `Ⱥ` itself has @@ -147,11 +147,11 @@ describe('lua function', function() eq({"yy","xx"}, exec_lua("return test_table")) -- type checked args - eq({false, 'Error executing lua: vim.schedule: expected function'}, - meth_pcall(exec_lua, "vim.schedule('stringly')")) + eq('Error executing lua: vim.schedule: expected function', + pcall_err(exec_lua, "vim.schedule('stringly')")) - eq({false, 'Error executing lua: vim.schedule: expected function'}, - meth_pcall(exec_lua, "vim.schedule()")) + eq('Error executing lua: vim.schedule: expected function', + pcall_err(exec_lua, "vim.schedule()")) exec_lua([[ vim.schedule(function() @@ -283,4 +283,9 @@ describe('lua function', function() assert(is_dc) end) + + it('vim.pesc', function() + eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]])) + eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) + end) end) -- cgit